Also call wxAuiManager::UnInit() when manager itself is destroyed

This completes the changes of the previous commit and should ensure that
UnInit() is always called, whoever is destroyed first -- the managed
window or the manager itself.

Also update the documentation to mention that calling UnInit()
explicitly is not necessary any longer.
This commit is contained in:
Vadim Zeitlin
2020-07-18 17:51:41 +02:00
parent f646532889
commit ceb21d5e86
3 changed files with 12 additions and 15 deletions

View File

@@ -484,11 +484,12 @@ public:
void StartPaneDrag(wxWindow* paneWindow, const wxPoint& offset); void StartPaneDrag(wxWindow* paneWindow, const wxPoint& offset);
/** /**
Uninitializes the framework and should be called before a managed frame or Dissociate the managed window from the manager.
window is destroyed. UnInit() is usually called in the managed wxFrame's
destructor. It is necessary to call this function before the managed frame This function may be called before the managed frame or window is
or window is destroyed, otherwise the manager cannot remove its custom event destroyed, but, since wxWidgets 3.1.4, it's unnecessary to call it
handlers from a window. explicitly, as it will be called automatically when this window is
destroyed, as well as when the manager itself is.
*/ */
void UnInit(); void UnInit();

View File

@@ -116,8 +116,6 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER); long style = wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER);
~MyFrame();
wxAuiDockArt* GetDockArt(); wxAuiDockArt* GetDockArt();
void DoUpdate(); void DoUpdate();
@@ -1016,11 +1014,6 @@ MyFrame::MyFrame(wxWindow* parent,
m_mgr.Update(); m_mgr.Update();
} }
MyFrame::~MyFrame()
{
m_mgr.UnInit();
}
wxAuiDockArt* MyFrame::GetDockArt() wxAuiDockArt* MyFrame::GetDockArt()
{ {
return m_mgr.GetArtProvider(); return m_mgr.GetArtProvider();

View File

@@ -633,6 +633,8 @@ wxAuiManager::wxAuiManager(wxWindow* managed_wnd, unsigned int flags)
wxAuiManager::~wxAuiManager() wxAuiManager::~wxAuiManager()
{ {
UnInit();
// NOTE: It's possible that the windows have already been destroyed by the // NOTE: It's possible that the windows have already been destroyed by the
// time this dtor is called, so this loop can result in memory access via // time this dtor is called, so this loop can result in memory access via
// invalid pointers, resulting in a crash. So it will be disabled while // invalid pointers, resulting in a crash. So it will be disabled while
@@ -953,9 +955,10 @@ void wxAuiManager::SetManagedWindow(wxWindow* wnd)
} }
// UnInit() must be called, usually in the destructor // UnInit() is called automatically by wxAuiManager itself when either the
// of the frame class. If it is not called, usually this // manager itself or its associated frame is destroyed, but can also be called
// will result in a crash upon program exit // explicitly, so make it safe to call it multiple times and just do nothing
// during any calls but the first one.
void wxAuiManager::UnInit() void wxAuiManager::UnInit()
{ {
if (m_frame) if (m_frame)