aboutsummaryrefslogtreecommitdiff
path: root/galaxies.c
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2020-07-05 19:32:26 -0400
committerSimon Tatham <anakin@pobox.com>2020-12-07 21:43:54 +0000
commit84cb4c6701e027090ff3fd955ce08065e20121b2 (patch)
tree67252d01e5233fe3d88e313341e75a78bd11d153 /galaxies.c
parent78bc9ea7f79f379634f822d5f95242900f5716b9 (diff)
downloadpuzzles-84cb4c6701e027090ff3fd955ce08065e20121b2.zip
puzzles-84cb4c6701e027090ff3fd955ce08065e20121b2.tar.gz
puzzles-84cb4c6701e027090ff3fd955ce08065e20121b2.tar.bz2
puzzles-84cb4c6701e027090ff3fd955ce08065e20121b2.tar.xz
Galaxies: fix assertion failure when adding out-of-bounds association.
Adding an association with an out-of-bounds square (i.e. by pressing Return with a dot selected, and then moving the cursor so the `opposite' arrow was off the screen) would cause space_opposite_dot() to return NULL, in turn causing ok_to_add_assoc_with_opposite_internal() to return false, failing the assertion. This assertion appears to have been introduced in 68363231.
Diffstat (limited to 'galaxies.c')
-rw-r--r--galaxies.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/galaxies.c b/galaxies.c
index 2761ed2..9172b90 100644
--- a/galaxies.c
+++ b/galaxies.c
@@ -382,12 +382,15 @@ static bool ok_to_add_assoc_with_opposite(
static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) {
space *opposite = space_opposite_dot(state, tile, dot);
- assert(ok_to_add_assoc_with_opposite_internal(state, tile, opposite));
+ if(opposite)
+ {
+ assert(ok_to_add_assoc_with_opposite_internal(state, tile, opposite));
- remove_assoc_with_opposite(state, tile);
- add_assoc(state, tile, dot);
- remove_assoc_with_opposite(state, opposite);
- add_assoc(state, opposite, dot);
+ remove_assoc_with_opposite(state, tile);
+ add_assoc(state, tile, dot);
+ remove_assoc_with_opposite(state, opposite);
+ add_assoc(state, opposite, dot);
+ }
}
static space *sp2dot(const game_state *state, int x, int y)