Re: [ROOT] Root GUI problem ...

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Fri Apr 05 2002 - 10:53:03 MEST


Hi Jacek,

  the BadWindow message is due to the fact that a widget is still
referenced while its associated window is already destroyed. This can
happen if in the dtors of the mainframe derived classes not all widgets
are deleted while their windows will be destroyed by the TGMainFrame
dtor (which calls DestroyWindow()). The error can also occur when Exit()
is called via a widget action and during Exit() this widget itself is
destroyed, on return from Exit() this widget is then still used which
might also cause a BadWindow.

Note that when everything is ok it is enough to have:

if (historyFrame) {
    delete historyFrame; // inherits from "public TGMainFrame"
    historyFrame = 0; // no cast needed
}
 
etc.


Cheers, Fons.


On Thu, 2002-04-04 at 19:33, Jacek M. Holeczek wrote:
> Hi,
> I encountered a stupid problem ... 
> First have a look at the following piece of code :
> -----------------------------------------
> void G4UIRoot::Exit() {
>   
>   gSystem->ProcessEvents();
>   
>   if( (UI = G4UImanager::GetUIpointer())) {
>     UI->SetCoutDestination(NULL);
>     UI->SetSession(NULL);
>     UI = G4UImanager::GetUIpointer();
>     gSystem->ProcessEvents();
>   }
>   
>   if (historyFrame) {
>     delete historyFrame; // inherits from "public TGMainFrame"
>     historyFrame = ((G4RootTextFrame *)0);
>     gSystem->ProcessEvents();
>   }
>   
>   if (outputFrame) {
>     delete outputFrame; // inherits from "public TGMainFrame"
>     outputFrame = ((G4RootTextFrame *)0);
>     gSystem->ProcessEvents();
>   }
>   
>   if (errorFrame) {
>     delete errorFrame; // inherits from "public TGMainFrame"
>     errorFrame = ((G4RootTextFrame *)0);
>     gSystem->ProcessEvents();
>   }
>   
>   if (mainFrame) {
>     delete mainFrame; // inherits from "public TGMainFrame"
>     mainFrame = ((G4RootMainFrame *)0);
>     gSystem->ProcessEvents();
>   }
>   
>   if (!existedRint) {
>     gApplication->Terminate(0); // Rint
>     gSystem->ProcessEvents();
>   }
>   
> }
> -----------------------------------------
> Then some explanations ...
> On "Exit" this is expected to close and destroy max. 4 of X11 windows
> (historyFrame, outputFrame, errorFrame, mainFrame).
> The first version of this routine had no "gSystem->ProcessEvents();" at
> all and then it was sure that a couple of :
> 	Error in <RootX11ErrorHandler>: BadWindow (invalid Window parameter) (XID: 54526138)
> 	Error ... BadDrawable ... (something like this)
> would appear after one tried to "Exit".
> Now, the routine contains a lot of "gSystem->ProcessEvents();" and in
> principle there are no X11 errors present ... unfortunately, from time to
> time (very rarely) the "BadWindow" errors still appears.
> Can one make this routine more robust ?
> Any help appreciated,
> Thanks in advance,
> Jacek.
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:48 MET