chiark / gitweb /
I've dithered a bit in the past about whether or not it's allowable
[sgt-puzzles.git] / midend.c
index 6d639eb908a75c814d7f57baaf06f556573204fa..64edfd3394f7544f1ab36b812f2413d77ff85983 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -217,6 +217,17 @@ void midend_size(midend *me, int *x, int *y, int expand)
     int min, max;
     int rx, ry;
 
+    /*
+     * We can't set the size on the same drawstate twice. So if
+     * we've already sized one drawstate, we must throw it away and
+     * create a new one.
+     */
+    if (me->drawstate && me->tilesize > 0) {
+        me->ourgame->free_drawstate(me->drawing, me->drawstate);
+        me->drawstate = me->ourgame->new_drawstate(me->drawing,
+                                                   me->states[0].state);
+    }
+
     /*
      * Find the tile size that best fits within the given space. If
      * `expand' is TRUE, we must actually find the _largest_ such
@@ -1169,8 +1180,11 @@ char *midend_solve(midend *me)
      * Now enter the solved state as the next move.
      */
     midend_stop_anim(me);
-    while (me->nstates > me->statepos)
+    while (me->nstates > me->statepos) {
        me->ourgame->free_game(me->states[--me->nstates].state);
+        if (me->states[me->nstates].movestr)
+            sfree(me->states[me->nstates].movestr);
+    }
     ensure(me);
     me->states[me->nstates].state = s;
     me->states[me->nstates].movestr = movestr;