chiark / gitweb /
Galaxies: fix assertion failure when adding out-of-bounds association.
authorFranklin Wei <franklin@rockbox.org>
Sun, 5 Jul 2020 23:32:26 +0000 (19:32 -0400)
committerSimon Tatham <anakin@pobox.com>
Mon, 7 Dec 2020 21:43:54 +0000 (21:43 +0000)
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.

galaxies.c

index 2761ed2523097e007bd371e72f86b7e4ab1913e5..9172b90e120322b84ac9b4e4c6e78c0bddb0a478 100644 (file)
@@ -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)