Failed to free a colormap entry in Xlib with XFreeColors()
Question
I allocate a color entry with the next code, then I use it to draw correctly:
char *color_name = "red";
XColor color, exact;
XAllocNamedColor(display, colormap, color_name, &color, &exact);
Then, when I don't need anymore the color entry, I try to free it:
XFreeColors(display, colormap, &color.pixel, 1, 0);
This call generates the next error:
Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 88 (X_FreeColors)
Serial number of failed request: 17
Current serial number in output stream: 19
Is there something I'm doing wrong? How can I free that color entry? That color entry should be freed?
Solution
Solved: I was doing two call to XFreeColors:
XFreeColors(display, colormap, &color.pixel, 1, 0);
XFreeColors(display, colormap, &exact.pixel, 1, 0);
The second call with exact must not be done, it's not necessary.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow