From: Daniel J S. <dan...@ie...> - 2004-08-17 22:58:05
|
Is joze out there? > The complete color map needs to be stored as part of the structure. > That is, plot->cmap needs to point at something that is dynamically > allocated independent of the current color map. I'll work on that > fix, but if this doesn't sound correct, let me know. Also, maybe > think if what I've added in this patch is adequate to fix the problem > when I have the plot->cmap problem fixed. That is, are there any > other details about the GC that also must be updated? I started on this one and soon realized that this code is already present. (The default "cmap" is used similar to zero when doing dynamic memory allocation.) So, I tracked down this problem to a line of code. The small change in the attached diff will solve the problem Petr found, but it also creates another. Here is the situation. That update of plot->cmap to point to the proper colormap is done inside PaletteMake. Here is the block of code: if (plot->cmap->allocated < min_colors && !recursion) { ReleaseColormap(plot); /* create a private colormap. */ fprintf(stderr, "switching to private colormap\n"); plot->cmap = (cmap_t *) malloc(sizeof(cmap_t)); assert(plot->cmap); CmapClear(plot->cmap); plot->cmap->colormap = XCreateColormap(dpy, root, vis, AllocNone); assert(plot->cmap->colormap); pr_color(plot->cmap); /* set default colors for lines */ RecolorWindow(plot); recursion = 1; PaletteMake(plot, (t_sm_palette *) 0); } else { This allocates memory for the map and then sets plot->cmap to point to it. If all things are hunky dory then, whenever plot->cmap is refered to in the future plot->cmap will point to the proper colormap. However, that test at the start: plot->cmap->allocated < min_colors I think that is the problem. The first time in, the min_colors will be 2 or 10 in one of the examples Petr gives. However, the default cmap, what plot->cmap points to by default has more than 10 allocated values. Hence, that test never passes and the code which dynamically allocates the cmap never gets called. So, remove that test as I did in the diff file. That fixes the problem of the palette being restored to the proper palette. Unfortunately, it's not creating the proper palette in the first place. (I has far more than the 2 or 10 colors requested.) I could look at it further, but the recursive nature of this routine causes me to initially punt to joze. Dan |