]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement delayed destruction for wxPopupTransientWindow.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 9 Oct 2011 22:02:02 +0000 (22:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 9 Oct 2011 22:02:02 +0000 (22:02 +0000)
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

include/wx/popupwin.h
src/common/popupcmn.cpp

index da479f31ba7488be6bfaf8737be605202e7f6511..03bb274c5a4d97486c7605e3211604d2f1c1f8dd 100644 (file)
@@ -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();
index f4b812330e39a3352990b41dd7cb979c6cd2d188..6aef738e9debfe94e1c2a7fbe3654503147086d4 100644 (file)
@@ -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();