Browse Source

Fix progression realloc bug

I wasn't actually telling the right size, so garbage data was being
read instead. It's good to know the game doesn't crash on this
anyways, I guess.

I also reduced the number of attempts made at picking the next puzzle
if the data set is small. There's now another condition to ensure the
next puzzle is different from the current one.
master
Macoy Madson 3 years ago
parent
commit
a7c0b389e8
  1. 17
      src/Main.cake

17
src/Main.cake

@ -518,13 +518,21 @@
(defun-local game-board-load-next-puzzle ()
(when g-num-progression-puzzles
(var g-previous-progression-puzzle (* progression-puzzle) g-current-progression-puzzle)
(pick-random-progression-puzzle)
(var num-attempts int 1)
(while (path g-current-progression-puzzle > is-solved)
;; Reasonable given how many puzzles someone might do in one sitting vs. total num puzzles
(var max-num-attempts int 200)
;; Don't try too hard when the data set is small
(when (< g-num-progression-puzzles max-num-attempts)
(set max-num-attempts (* 2 g-num-progression-puzzles)))
(while (or (= g-previous-progression-puzzle g-current-progression-puzzle) ;; Try to ensure change
(path g-current-progression-puzzle > is-solved)) ;; Only pick non-solved
(pick-random-progression-puzzle)
(incr num-attempts)
;; Reasonable given how many puzzles someone might do in one sitting vs. total num puzzles
(when (= num-attempts 200)
(when (= num-attempts max-num-attempts)
(SDL_Log "Max attempts reached for random puzzle! Has the app not been restarted in a long time?\n")
(break)))
(unless (< (path g-current-progression-puzzle > index) g-num-puzzles)
@ -618,7 +626,8 @@
(when (and g-num-progression-puzzles
(!= g-num-progression-puzzles num-unsolved-puzzles))
(set g-progression-puzzles
(type-cast (realloc g-progression-puzzles num-unsolved-puzzles)
(type-cast (realloc g-progression-puzzles
(* (sizeof (type progression-puzzle)) num-unsolved-puzzles))
(* progression-puzzle)))
(set g-num-progression-puzzles num-unsolved-puzzles))

Loading…
Cancel
Save