[comp.windows.x] Motif Colormap Problem

tmwalden@bbn.com (Tim M. Walden) (01/08/91)

I have created a xmDrawingAreaWidgetClass widget and am trying to install a
colormap into it.  The procedure I am using works on an 8-bit-deep display
(Sun 3/60 running X11R4) but dies on a 4-bit-deep display (Cetia running X11R3).
I am setting up the colormap as follows:

load_colormap(window)
    int         window;
{
    extern MAP_WINDOW   maps[NUM_WINDOWS];
    Display     *dpy = XtDisplay(maps[window].canvas);
    Colormap    default_colormap;
    Colormap    my_colormap;
    XColor      Colors[NUM_COLORS];
    int         i;
    int                 red[NUM_COLORS],
                        green[NUM_COLORS],
                        blue[NUM_COLORS];
    extern Widget toplevel;
    int                colors[NUM_COLORS];

    red[BLACK]      = 0;    green[BLACK]      = 0;    blue[BLACK]      = 0;
    red[WHITE]      = 255;  green[WHITE]      = 255;  blue[WHITE]      = 255;
    red[VIOLETRED]  = 208;  green[VIOLETRED]  = 32;   blue[VIOLETRED]  = 144;
    red[YELLOW]     = 255;  green[YELLOW]     = 255;  blue[YELLOW]     = 0;
    red[DARK_BLUE]  = 0;    green[DARK_BLUE]  = 0;    blue[DARK_BLUE]  = 128;
    red[RED]        = 255;  green[RED]        = 0;    blue[RED]        = 0;
    red[NAVY]       = 0;    green[NAVY]       = 0;    blue[NAVY]       = 128;
    red[GRAY_25]    = 77;   green[GRAY_25]    = 77;   blue[GRAY_25]    = 77;
    red[ORANGE]     = 255;  green[ORANGE]     = 165;  blue[ORANGE]     = 0;
    red[GRAY_75]    = 191;  green[GRAY_75]    = 191;  blue[GRAY_75]    = 191;
    red[BACKGROUND] = 0;    green[BACKGROUND] = 0;    blue[BACKGROUND] = 0;
    red[GREEN]      = 0;    green[GREEN]      = 255;  blue[GREEN]      = 0;
    red[DARKGREEN]  = 0;    green[DARKGREEN]  = 100;  blue[DARKGREEN]  = 0;
    red[PURPLE]     = 160;  green[PURPLE]     = 32;   blue[PURPLE]     = 240;
    red[BLUE]       = 0;    green[BLUE]       = 0;    blue[BLUE]       = 255;
    red[MAGENTA]    = 207;  green[MAGENTA]    = 0;    blue[MAGENTA]    = 255;

    default_colormap = DefaultColormap(dpy, DefaultScreen(dpy));
    for( i = 0; i < NUM_COLORS; i++ ) {
        Colors[i].pixel = i;
        Colors[i].flags = DoRed|DoGreen|DoBlue;
    }
    XQueryColors(dpy, default_colormap, Colors, NUM_COLORS);

    XAllocColorCells(dpy, default_colormap, False, plane_masks,
         0, colors, NUM_COLORS);

    for( i = 0; i < NUM_COLORS; i++ ) {
	Colors[i].pixel = colors[i];
        Colors[i].red   = red[i] * 256;
        Colors[i].green = green[i] * 256;
        Colors[i].blue  = blue[i] * 256;
    }


    XStoreColors(dpy, default_colormap, Colors, NUM_COLORS);

    maps[window].colormap = (unsigned long *) malloc(NUM_COLORS * sizeof(long));

    for (i = 0; i < NUM_COLORS; i++ ) 
	maps[window].colormap[i] = Colors[i].pixel;

}


This routine completes without a problem but the system later dies upon the
first time I try to do something to the Drawing Area.  The error message is:

X Protocol error:  BadAccess, attempt to access private resource denied
  Major opcode of failed request:  89 (X_StoreColors)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x181a
  Serial number of failed request:  602
  Current serial number in output stream:  912


I have also tried this with a StaticColor and PseudoColor visual.  They both
die the same death.  Any help in this matter is greatly appreciated.  Response
via email is preferred.

Tim Walden
BBN Inc.
tmwalden@bbn.com