[comp.windows.x] Quirky XtDestroyApplicationContext......???????

fbm@ptcburp.ptcbu.oz.au (Farrell McKay) (05/28/91)

Below is a very short X Toolkit based program.  It just creats a widget,
realizes it, and then exits.  Pretty complex, eh?  The only problem is
that when I compile and run it on my machine, I get an error from
XtDestroyApplicationContext.

Has anyone else out there seen this behaviour?  Does the same thing
happen for you?


      -m-------  Farrell McKay,                   fbm@ptcburp.oz.au
    ---mmm-----  Pyramid Technology Aust.,        ...!munnari!ptcburp.oz!fbm
  -----mmmmm---  Research Park, Bond University,  +61 75 950256
-------mmmmmmm-  Gold Coast, Qld 4229, AUSTRALIA  +61 75 522475 FAX

---------------------------------- cut cut -------------------------------------

#include	<stdio.h>
#include	<X11/Intrinsic.h>	
#include	<X11/Shell.h>
#include	<X11/Xaw/Label.h>	

String fallbacks[] = {
	"*Label.Label:    This is a label widget", NULL
};

XtAppContext	app;
Widget		top;
Widget		label;

/*
 * This program creates a widget, realizes it, and then exits.
 * To compile this program simply type:-
 * cc -DXAW_BC it.c -o it -lXaw -lXmu -lXt -lXext -lX11
 *
 * Running this program generates the following message from within
 * XtCloseDisplay within XtDestroyApplication:-
 *
 * X Error of failed request:  BadAccess (attempt to access private resource denied)
 *   Major opcode of failed request:  88 (X_FreeColors)
 *   Minor opcode of failed request:  0
 *   Resource id in failed request:  0x4077ffff
 *   Serial number of failed request:  27
 *   Current serial number in output stream:  30
 *
 */
main(argc, argv)
int	argc;
char	*argv[];
{
	top = XtAppInitialize(&app, "Xlabel", NULL, 0,
					&argc, argv, fallbacks, NULL, 0);

	label = XtCreateManagedWidget("label", labelWidgetClass, top, 
							NULL, 0);

	XtRealizeWidget(top);
	XtDestroyApplicationContext(app);
	exit(0);
}

swick@athena.mit.EDU (Ralph Swick) (05/30/91)

     * Running this program generates the following message from within
     * XtCloseDisplay within XtDestroyApplication:-
     *
     * X Error of failed request:  BadAccess (attempt to access private resource denied)
     *   Major opcode of failed request:  88 (X_FreeColors)

Reproducing this is going to be very difficult without knowing
the contents of your resource files, but let me guess;

If you don't have R4 patched to fix #18 then some cases of StringToPixel
conversion (i.e. Alloc*Color) failures can cause this symptom.  (The
converter neglects to record the allocation failure and later on
cleanup from XtDestroyApplicationContext() it tries to free an
unallocated pixel.)

fbm@ptcburp.ptcbu.oz.au (Farrell McKay) (05/31/91)

swick@athena.mit.EDU (Ralph Swick) writes:

> If you don't have R4 patched to fix #18 then some cases of StringToPixel
> conversion .....

Since I first posted this article, I've been kicking myself for not detailing
my X environment.  Sorry.  I am using X11R4 patch level 18.  The only resources
of relevance to the program (stored in the resource property on the server)
were:-

*borderColor:			white
*background:			black

It turns out that removing these resources makes the problem go away.
It also turns out that the problem can be demonstrated without creating
or realizing any widgets!  Here is a simpler version of the original program
which exhibits the same behaviour:-


      -m-------  Farrell McKay,                   fbm@ptcburp.oz.au
    ---mmm-----  Pyramid Technology Aust.,        ...!munnari!ptcburp.oz!fbm
  -----mmmmm---  Research Park, Bond University,  +61 75 950256
-------mmmmmmm-  Gold Coast, Qld 4229, AUSTRALIA  +61 75 522475 FAX

---------------------------------- cut cut -------------------------------------
#include	<X11/Intrinsic.h>	

XtAppContext	app;
Widget		top;

/*
 * This program creates an application context, destroys it, and then exits.
 * To compile this program simply type:-
 * cc it.c -o it -lXt -lX11
 *
 * Running this program generates the following message from within
 * XtCloseDisplay within XtDestroyApplication:-
 *
 * X Error of failed request:  BadAccess (attempt to access private resource denied)
 *   Major opcode of failed request:  88 (X_FreeColors)
 *   Minor opcode of failed request:  0
 *   Resource id in failed request:  0x4077ffff
 *   Serial number of failed request:  7
 *   Current serial number in output stream:  10
 *
 */
main(argc, argv)
int	argc;
char	*argv[];
{
	top = XtAppInitialize(&app, "It", NULL, 0, &argc, argv, NULL, NULL, 0);
	XtDestroyApplicationContext(app);
	exit(0);
}