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;
{
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 ();
}
}
+/* 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,
setup_colormap (dpy, &wattr, &colors, &n_colors);
erase_full_window (dpy, window);
model_initialize (model);
+ model_step (model, &history[0]);
pos = 1;
wrapped = 0;
}
}
i_restart = (i_restart + 1) % n_restart;
+
+ if (i_restart == 0)
+ {
+ /* Clean up after completing a simulation. */
+ free_colormap (dpy, &wattr, &colors, n_colors);
+ }
}
}