I've came upon some issues with closing and destroying windows already closed by user.
Here is sample code of invoking wxFrame d-tor after user closed the window:
Code: Select all
#include <wx/wx.h>
class app : public wxApp {
wxFrame* mainFrame;
public:
bool OnInit() {
mainFrame = new wxFrame(NULL, wxID_ANY, L"Sample");
mainFrame->Show();
return true;
}
app() : mainFrame(NULL), wxApp() { }
~app() {
// Regular, default situation: class is destroying object that was created by it .
delete mainFrame; /** Applications __CRASHES__ here [MinGW] **/
// Also, some of other wxWindow or wxFrame closing/destryoing functions wouldn't work ( i mean would crash app )
// mainFrame->Destroy(); mainFrame->Close();
// but also some simple examinations, like
// mainFrame->IsBeingDeleted();
}
};
IMPLEMENT_APP(app);
Isn't there some enormous mistake inside wxFrame/wxWindow class? Is the destructor already called?
Regular, code-invoked deletion, like:
Code: Select all
frame->Destroy(); delete frame;
I've came up with an idea to check withing a function is a frame/window already deleted. It's (undocumented...) wxWindow->GetHWND(); It does returns 0 if the window is destroyed.
Would work fine with functions like Destroy()....
But I really wanna clear up my pointers before destructing my class [ of course above code is just simple example, I have pretty much more complex class hierarchy going in my project ]. Or are they already cleared, from inside-wxWindow-class?
I'm using newest MinGW under Windows 7.
wxWidgets: 2.93. Monolithic, dynamic-library build.
Thank you in advance for your answers!