diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-10-06 19:49:05 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-10-06 19:49:05 +0100 |
| commit | f6b2f47ef3feca86b0d16c28b607acdea5fc6235 (patch) | |
| tree | 3d5b4cd17fbd41967e71626dd50ac7e6b6eab2b5 /midend.c | |
| parent | a58c1b216bb1d4547f7b2ef2703fe2d0cd3b5cac (diff) | |
| download | puzzles-f6b2f47ef3feca86b0d16c28b607acdea5fc6235.zip puzzles-f6b2f47ef3feca86b0d16c28b607acdea5fc6235.tar.gz puzzles-f6b2f47ef3feca86b0d16c28b607acdea5fc6235.tar.bz2 puzzles-f6b2f47ef3feca86b0d16c28b607acdea5fc6235.tar.xz | |
Fix assertion failure if you Undo right at startup.
The initial call to midend_new_game() was creating a partial
serialisation containing no game states at all, which meant that if
your first UI action was an undo operation, the game would try to
deserialise that and complain that it was incomplete. Now we detect
that in advance and don't create a useless serialisation in the first
place.
Diffstat (limited to 'midend.c')
| -rw-r--r-- | midend.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -403,7 +403,20 @@ static void newgame_serialise_write(void *ctx, const void *buf, int len) void midend_new_game(midend *me) { me->newgame_undo_len = 0; - midend_serialise(me, newgame_serialise_write, me); + if (me->nstates != 0) { + /* + * Serialise the whole of the game that we're about to + * supersede, so that the 'New Game' action can be undone + * later. But if nstates == 0, that means there _isn't_ a + * current game (not even a starting position), because this + * is the initial call to midend_new_game when the midend is + * first set up; in that situation, we want to avoid writing + * out any serialisation, because it would be useless anyway + * and just confuse us into thinking we had something to undo + * to. + */ + midend_serialise(me, newgame_serialise_write, me); + } midend_stop_anim(me); midend_free_game(me); |