Re: popup menu causes crash

Steve Lamont (spl@szechuan.ucsd.edu)
Thu, 15 May 97 06:38:34 PDT

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I'm having some difficulty with popup menus. I don't know whether
> it's my programming error or a bug. It would be nice if an expert could look
> at it.
>
> I copied bits from the demo program pup to make this. What I find is if the
> form with the menu:
>
> is shown
> menu selected
> form hidden
> form shown again
> menu selected again
>
> then the program terminates with BadDrawable in X_GetGeometry:

The problem is that when you hide a Form, XForms destroys the Window
and all the associated resources connected to it, so when you fire off
your menu for the second time, it's looking at resources that no
longer exist. Move the menu create stuff into the callback.

My tack in dealing with menus and other transient objects of that
nature is to create them on the fly (it's very quick) and then destroy
them as soon as they've popped down. I generally don't even create
them until the Menu button is actually pressed. I've not had the need
to do this with cascaded menus but I don't see any reason why this
approach wouldn't work in that case as well.

Another method of dealing with the problem is to do an XUnmapWindow()
instead of a fl_hide_form(). Of course, this means you've got a
special case at the first instantiation of the Form so this may be a
suboptimal answer from a programming standpoint since it requires a
bit more bookkeeping (you have to do an XMapWindow() on all subsequent
entries into the function).

I can argue that this sort of behavior (destorying Windows) is
something of a misfeature in XForms but I can also understand why it
might have been done -- it simplifies the internal bookkeeping that
XForms has to do when showing and hiding windows.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/xforms-archive/