From: brownp@cs.unc.edu (Peter Brown)
Newsgroups: comp.windows.x.motif
Subject: Motif and 24-bit DirectColor visuals
Date: 20 Aug 92 01:52:54 GMT
Distribution: comp
Organization: UNC Department of Computer Science

I'm trying to write an image-display application under Motif, and am
having trouble getting Motif widgets to function correctly under a
24-bit DirectColor visual.  It seems to have trouble getting the GCs
it needs.  The following code (I radically simplified this for
debugging):

main(unsigned int argc, char** argv)
{
    XtToolkitInitialize();
    XtAppContext app = XtCreateApplicationContext();
    Display* disp = XtOpenDisplay(app, NULL, NULL, "Newvis", 
				  NULL, 0, &argc, argv);
    XSynchronize(disp, True);

    XVisualInfo vinfo;
    if (XMatchVisualInfo
	(disp, DefaultScreen(disp), 24, DirectColor, &vinfo))
	printf("Got a DirectColor visual, ID 0x%x\n", vinfo.visualid);
    else printf("No DirectColor visual could be found\n");

    Colormap cmap = XCreateColormap(disp, RootWindow(disp, DefaultScreen(disp)),
				    vinfo.visual, AllocAll);

    Widget top_shell = XtVaAppCreateShell
	(NULL, "Newvis", applicationShellWidgetClass, disp, 
	 XmNvisual, vinfo.visual, XmNdepth, vinfo.depth, XmNcolormap, cmap, 
	 NULL);

    Widget main_window = XtVaCreateWidget
	("main_window", xmFormWidgetClass, top_shell, NULL);

    XtVaSetValues(main_window,
		  XmNallowOverlap, False,
		  NULL);

    XtManageChild(main_window);
    XtRealizeWidget(top_shell);
    XtAppMainLoop(app);
}

produces the following error message:

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  55 (X_CreateGC)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x400007
  Serial number of failed request:  48
  Current serial number in output stream:  49

This happens in the call to XtVaCreateWidget (verified by debugger and
by removing the offending code).  The shell widget comes up fine, if
it's alone; the main_window widget doesn't generate an error if I make
it a BulletinBoard, say, instead of a Form (in that case, other
widgets, not always Forms, which I need to add generate similar errors
- always a BadMatch error occurring in an XCreateGC request).  I have
also found that I can escape the error by hard-coding background and
borderColor values (I can't specify them in a resource file, I have to
hard-code them for each widget).  A call to XtGetGC(top_shell) happily
returns a GC; apparently the Form, DrawingArea, and MenuBar widgets
can't use that GC, however.

I'm running my client on a DECstation 5000/120 running ULTRIX 4.2A;
the server can be either the same DEC or an HP 9000/750 running HP-UX
8.05, without significant change in the error messages.  (The HP seems
to be a _little_ more tolerant, but not enough to allow me to get my
work done.)

Has anybody else seen this sort of thing?  Is there something obvious
I need to do that I'm not doing?

Thanks,
--
--Peter (brownp@cs.unc.edu)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"In this is love, not that we loved God but that he loved us and sent
his Son to be the atoning sacrifice for our sins." - I John 4:10