How to use the graphics library in a stable way

[quote=“bellenot”]Hi,

Please try to replace:

for (size_t It = 0; It < MdiFrames.size (); ++It) { MdiFrames[It]->Cleanup (); MdiFrames[It]->DeleteWindow (); }by:for (size_t It = 0; It < MdiFrames.size (); ++It) { delete MdiFrames[It]; }
Since everything is done in the TGMdiFrame destructor:

[code]//______________________________________________________________________________
TGMdiFrame::~TGMdiFrame()
{
// TGMdiFrame destructor.

Cleanup();
fMain->RemoveMdiFrame(this);
}
[/code]
[/quote]

With these changes the crashes indeed disappear. Does this prove that there is a problem in the DeleteWindow () method?

Hi,
Maybe… But you have to be very careful in multithreaded application, or when deleting object. The problem in you case could be also due to the MdiFrames.clear (); code. When calling clear() method of a vector, all the elements of the vector are dropped: their destructors are called. That means TGFrame destructors are called, and then the ReallyDelete is called via the single shot timer (triggered in TGFrame::DeleteWindow())
And if the frame has already been deleted, you have a X11 error with BadWindow (invalid Window parameter) and a segv…
Bertrand.

[quote=“bellenot”]Hi,
Maybe… But you have to be very careful in multithreaded application, or when deleting object. The problem in you case could be also due to the MdiFrames.clear (); code. When calling clear() method of a vector, all the elements of the vector are dropped: their destructors are called. That means TGFrame destructors are called, and then the ReallyDelete is called via the single shot timer (triggered in TGFrame::DeleteWindow())
And if the frame has already been deleted, you have a X11 error with BadWindow (invalid Window parameter) and a segv…
Bertrand.[/quote]

In my case the vector contains only pointers. (It is not a vector of MdiFrames, but a vector of pointers to MdiFrames.) If the vector is cleared, only the pointers are “destructed”, not the MdiFrames. A pointer is “destructed” without any action.
So, I do not get your point.

Oh yes, you’re right. :blush: Sorry for the trouble.
Bertrand.