X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fcritical.c;h=5acb478d2ff58f0b0d0f94c75fa8d138e4c529eb;hp=5a6fae2a8014324eb9422a0cc53a6befb3801e3f;hb=c28aecf9fc41e3a03494bacf7279745425e2fa18;hpb=723c9eeee862766a1534b2ce17b78adbfac1c3be diff --git a/hacks/critical.c b/hacks/critical.c index 5a6fae2a..5acb478d 100644 --- a/hacks/critical.c +++ b/hacks/critical.c @@ -96,7 +96,7 @@ model_allocate (int model_w, int model_h) model->width = model_w; model->height = model_h; - model->cells = malloc (sizeof (int) * model_w * model_h); + model->cells = malloc (sizeof (unsigned short) * model_w * model_h); if (!model->cells) return 0; @@ -128,7 +128,7 @@ model_initialize (CriticalModel *model) { int i; - for (i = model->width * model->height; i >= 0; i--) + for (i = model->width * model->height - 1; i >= 0; i--) { model->cells[i] = (unsigned short) random (); } @@ -237,6 +237,17 @@ setup_colormap (Display *dpy, XWindowAttributes *wattr, } +/* Free allocated colormap created by setup_colormap. */ +static void +free_colormap (Display *dpy, XWindowAttributes *wattr, + XColor **colors, int n_colors) +{ + free_colors (dpy, wattr->colormap, *colors, n_colors); + free (*colors); +} + + + /* Draw one step of the hack. Positions are cell coordinates. */ static void draw_step (CriticalSettings *settings, @@ -341,6 +352,7 @@ screenhack (Display *dpy, Window window) setup_colormap (dpy, &wattr, &colors, &n_colors); erase_full_window (dpy, window); model_initialize (model); + model_step (model, &history[0]); pos = 1; wrapped = 0; } @@ -382,5 +394,11 @@ screenhack (Display *dpy, Window window) } i_restart = (i_restart + 1) % n_restart; + + if (i_restart == 0) + { + /* Clean up after completing a simulation. */ + free_colormap (dpy, &wattr, &colors, n_colors); + } } }