From: Vadim Zeitlin Date: Sun, 9 Oct 2011 22:02:02 +0000 (+0000) Subject: Implement delayed destruction for wxPopupTransientWindow. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f9e19204bf8327f1e71f127e5542ee8306282280 Implement delayed destruction for wxPopupTransientWindow. Windows of this class can be destroyed at any moment, even while some events are still being processed, so delay the real destruction until we can be sure that it's safe to delete the window. This fixes problems (crashes due to dangling pointers) when the object is deleted from the overridden OnDismiss(), for example. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69349 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/popupwin.h b/include/wx/popupwin.h index da479f31ba..03bb274c5a 100644 --- a/include/wx/popupwin.h +++ b/include/wx/popupwin.h @@ -112,6 +112,9 @@ public: // Overridden to grab the input on some plaforms virtual bool Show( bool show = true ); + // Override to implement delayed destruction of this window. + virtual bool Destroy(); + protected: // common part of all ctors void Init(); diff --git a/src/common/popupcmn.cpp b/src/common/popupcmn.cpp index f4b812330e..6aef738e9d 100644 --- a/src/common/popupcmn.cpp +++ b/src/common/popupcmn.cpp @@ -387,6 +387,20 @@ bool wxPopupTransientWindow::Show( bool show ) return ret; } +bool wxPopupTransientWindow::Destroy() +{ + // The popup window can be deleted at any moment, even while some events + // are still being processed for it, so delay its real destruction until + // the next idle time when we're sure that it's safe to really destroy it. + + wxCHECK_MSG( !wxPendingDelete.Member(this), false, + wxS("Shouldn't destroy the popup twice.") ); + + wxPendingDelete.Append(this); + + return true; +} + void wxPopupTransientWindow::Dismiss() { Hide();