Trimmed down NEDsim to a single CPU, single thread, 64MB RAM, 64k element stack,...
[screensavers] / hacks / NEDsim / NEDsim.c
index df95105..73c72f9 100644 (file)
@@ -677,8 +677,16 @@ NEDsim_event(Display * dpy, Window win, void * closure, XEvent * event)
 static void
 NEDsim_free(Display * dpy, Window win, void * closure)
 {
 static void
 NEDsim_free(Display * dpy, Window win, void * closure)
 {
-    // TODO: Replace all this with proper code to free everything.
     struct NEDsim * nedsim = closure;
     struct NEDsim * nedsim = closure;
+
+    if (nedsim->nedstate != NULL) {
+        free(nedsim->nedstate->active_thread->psw);
+        free(nedsim->nedstate->active_thread);
+        free(nedsim->nedstate->hack);
+        free(nedsim->nedstate);
+    }
+
+    // TODO: Replace all this with proper code to free everything related to the screensaver itself.
     XFreeGC(nedsim->dpy, nedsim->gc);
     free(nedsim);
 }
     XFreeGC(nedsim->dpy, nedsim->gc);
     free(nedsim);
 }
@@ -781,8 +789,12 @@ NEDsim_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsign
     XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
     /* Only restart the simulation if the window changed size.                */
     if (nedsim->dpy_width != xgwa.width || nedsim->dpy_height != xgwa.height) {
     XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
     /* Only restart the simulation if the window changed size.                */
     if (nedsim->dpy_width != xgwa.width || nedsim->dpy_height != xgwa.height) {
-        NEDsim_free(dpy, win, closure);
-        closure = NEDsim_init(dpy, win);
+        struct NEDstate * original_nedstate = nedsim->nedstate;
+        nedsim->nedstate = NULL;
+        NEDsim_free(dpy, win, nedsim);
+        struct NEDsim * new_nedsim = NEDsim_init(dpy, win);
+        new_nedsim->nedstate = original_nedstate;
+        closure = new_nedsim;
     }
 }
 
     }
 }