[comp.windows.x.motif] Popup of a popup BUG.

ephrem@oakhill.UUCP (Ephrem Chemaly) (12/11/90)

I have included a sample source code for a client that crashes.

Here is a brief description of the problem.

I create a motif widget called 'button'.  This widget pops up another widget
'popup1' and 'button' is set to insensitive.  'popup1' is a Selection widget.
If I push the help button in 'popup1', I popup the 'popup2' widget, and set
'popup1' to insensitive.  When I am done, I pop down popup2, and set popup1
to sensitive. Then if I popdown 'popup1' the application crashes.

Why is that?

I have included the source code.  There are two ways to compile this file.

cc -L/usr/local/lib -o learn learn.c -lXm -lXtm -lXmu -lXt -lX11

which works, and

cc -L/usr/local/lib -Dsensitive -o learn learn.c -lXm -lXtm -lXmu -lXt -lX11

which sets the preprocessor's 'sensitive' flag which I use with #ifdef to
compile some extra code.  This does not work.  I get the following error:
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  62 (X_CopyArea)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x70001d
  Serial number of failed request:  406
  Current serial number in output stream:  406
So the problem is isolated at the extra line compiled near #ifdef sensitive
which sets popup1 the insensitive.

I see this problem an my Sun 3/260 with X11R4, and A/UX with X11R3.

Please use the address below to reply by e-mail.

Regards,
Ephrem A. Chemaly

+=========================================================================+
| Motorola Inc.                            Ephrem A. Chemaly              |
|                                          6501 William Cannon Drive West |
|                                          Austin, Texas 78735 U.S.A.     |
|                                          Mail Drop: OE-21               |
|                                          (512) 891-2760                 |
|                                                                         |
| Internal Addr: ephrem@soleil-tx (or at) oakhill!soleil-tx!ephrem        |
| Internet Addr: ...!soleil-tx.sps.mot.com!ephrem                         |
| UUCP Address:  oakhill!soleil-tx!ephrem@cs.utexas.edu                   |
+=========================================================================+

----------- THIS IS THE SOURCE CODE BELOW -------------------------------------

/******************************************************************************
*
* Compilation (Method 1 that works):
*       cc -L/usr/local/lib -o learn learn.c -lXm -lXtm -lXmu -lXt -lX11
* Compilation (Method 2 that does not work):
*       cc -L/usr/local/lib -Dsensitive -o learn learn.c -lXm -lXtm -lXmu -lXt -lX11
*
******************************************************************************/

#include <Xm/Xm.h>
#include <Xm/MainW.h>
#include <Xm/Frame.h>
#include <Xm/Form.h>
#include <Xm/DialogS.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/SelectioB.h>
#include <Xm/MessageB.h>

Widget	popup1, popup2, button;

/*******************************************************************************
********** Kill2(): Kill the second level.						************
*******************************************************************************/

void Kill2(widget, closure, callData)
Widget widget;
caddr_t closure;		/* unused */
caddr_t callData;		/* unused */
{
XtDestroyWidget(popup2);

XtSetSensitive(popup1, TRUE);

}
/*******************************************************************************
********** Kill1(): Kill the first level.						************
*******************************************************************************/

void Kill1(widget, closure, callData)
Widget widget;
caddr_t closure;		/* unused */
caddr_t callData;		/* unused */
{
XtDestroyWidget(popup1);

XtSetSensitive(button, TRUE);

}
/*******************************************************************************
********** Popup2(): Popup the second level.						************
*******************************************************************************/

void Popup2(widget, closure, callData)
Widget widget;
caddr_t closure;		/* unused */
caddr_t callData;		/* unused */
{
Arg     args[10];
static  XtCallbackRec callback[2];
static	XtCallbackRec KillCallback[2];
int     n;

#ifdef sensitive
XtSetSensitive(widget, FALSE);
#endif

n = 0;
XtSetArg(args[n], XmNautoUnmanage, False); n++;
KillCallback[0].callback = Kill2;
KillCallback[0].closure = (caddr_t)NULL;
XtSetArg(args[n], XmNokCallback, KillCallback); n++;
XtSetArg(args[n], XmNcancelCallback, KillCallback); n++;
XtSetArg(args[n], XmNhelpCallback, KillCallback); n++;
popup2 = XmCreateInformationDialog(widget, "Popup1", args, n);
XtManageChild(popup2);
}
/*******************************************************************************
********** Popup1(): Popup the first level.							************
*******************************************************************************/

void Popup1(widget, closure, callData)
Widget widget;
caddr_t closure;		/* Widget */
caddr_t callData;
{
Arg		args[10];
static	XtCallbackRec HelpCallback[2];
static	XtCallbackRec KillCallback[2];
int		n;

XtSetSensitive(widget, FALSE);

n = 0;
XtSetArg(args[n], XmNautoUnmanage, False); n++;
HelpCallback[0].callback = Popup2;
HelpCallback[0].closure = (caddr_t)NULL;
XtSetArg(args[n], XmNhelpCallback, HelpCallback); n++;
KillCallback[0].callback = Kill1;
KillCallback[0].closure = (caddr_t)NULL;
XtSetArg(args[n], XmNokCallback, KillCallback); n++;
XtSetArg(args[n], XmNcancelCallback, KillCallback); n++;
popup1 = XmCreateSelectionDialog(widget, "Popup1", args, n);
XtManageChild(popup1);
}
/*******************************************************************************
********** main(): main function for this program.					************
*******************************************************************************/

void main(argc, argv)
unsigned int argc;
char **argv;
{
Widget	topLevel, BaseFrame, frame;
Arg		args[10];
static	XtCallbackRec callback[2];
int		n, i;

/* Initialize the X toolkit. */
topLevel = XtInitialize(argv[0], "Learn", NULL, NULL, &argc, argv);
n = 0;
BaseFrame = XtCreateManagedWidget(
			"clientBaseFrame",
			xmMainWindowWidgetClass,
			topLevel,
			args,
			n);

frame = XmCreateFrame(BaseFrame, "Frame", args, n);
XtManageChild(frame);

n = 0;
callback[0].callback = Popup1;
callback[0].closure = (caddr_t)NULL;
XtSetArg(args[n], XmNactivateCallback, callback); n++;
button = XmCreatePushButton(frame, "Button", args, n);
XtManageChild(button);

/* Display the widgets. */
XtRealizeWidget(topLevel);

/* Start the main event loop. */
XtMainLoop();
}

/*
Please use the address below to reply by e-mail.

Regards,
Ephrem A. Chemaly

+=========================================================================+
| Motorola Inc.                            Ephrem A. Chemaly              |
|                                          6501 William Cannon Drive West |
|                                          Austin, Texas 78735 U.S.A.     |
|                                          Mail Drop: OE-21               |
|                                          (512) 891-2760                 |
|                                                                         |
| Internal Addr: ephrem@soleil-tx (or at) oakhill!soleil-tx!ephrem        |
| Internet Addr: ...!soleil-tx.sps.mot.com!ephrem                         |
| UUCP Address:  oakhill!soleil-tx!ephrem@cs.utexas.edu                   |
+=========================================================================+
*/

nazgul@alphalpha.com (Kee Hinckley) (12/11/90)

> I create a motif widget called 'button'.  This widget pops up another widget
> 'popup1' and 'button' is set to insensitive.  'popup1' is a Selection widget.
> If I push the help button in 'popup1', I popup the 'popup2' widget, and set
> 'popup1' to insensitive.  When I am done, I pop down popup2, and set popup1
> to sensitive. Then if I popdown 'popup1' the application crashes.
> 
> Why is that?
Because you aren't using Motif 1.1.

Seriously.  Prior to 1.1, and in fact, prior to patchlevel 14 or so of the
R4 Intrinsics, you should never delete a widget.  It will work sometimes,
but both Motif and the Intrinsics were pretty bad about handling
dynamic creating and deletion of widgets.  There are problems with
space not being freed, there are problems with using space that *has*
been freed.  All in all it was a real mess.  That is the major reason
that we switched to 1.1.  (Your program, for what it's worth, works fine 
under my version of 1.1.)
				-kee