]> git.saurik.com Git - wxWidgets.git/commitdiff
Notify if the grid is being destroyed in an event generated by it
authorJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 10 Sep 2009 14:15:32 +0000 (14:15 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 10 Sep 2009 14:15:32 +0000 (14:15 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/propgrid.h
src/propgrid/propgrid.cpp

index 40350413b3b5ee68b43ea2cb2ee2d65ab1beb8a6..da4d269e1d527b6facb4f6d7fb08edfab56fe25a 100644 (file)
@@ -1772,6 +1772,9 @@ protected:
     // handling mess).
     wxWindow*           m_curFocused;
 
+    // Event currently being sent - NULL if none at the moment
+    wxPropertyGridEvent*    m_processedEvent;
+
     // Last known top-level parent
     wxWindow*           m_tlp;
 
index fedc84a7c0830f699b8ae7865ba62981333eccc8..963279ad367b3ed3e182fc6cfc7d62fcbc357fa0 100644 (file)
@@ -431,6 +431,7 @@ void wxPropertyGrid::Init1()
     m_labelEditorProperty = NULL;
     m_eventObject = this;
     m_curFocused = NULL;
+    m_processedEvent = NULL;
     m_sortFunction = NULL;
     m_inDoPropertyChanged = 0;
     m_inCommitChangesFromEditor = 0;
@@ -579,6 +580,23 @@ wxPropertyGrid::~wxPropertyGrid()
 {
     size_t i;
 
+    if ( m_processedEvent )
+    {
+        // All right... we are being deleted while wxPropertyGrid event
+        // is being sent. Make sure that event propagates as little
+        // as possible (although usually this is not enough to prevent
+        // a crash).
+        m_processedEvent->Skip(false);
+        m_processedEvent->StopPropagation();
+
+        // Let's use wxMessageBox to make the message appear more
+        // reliably (and *before* the crash can happend).
+        ::wxMessageBox("wxPropertyGrid was being destroyed in an event "
+                       "generated by it. This usually leads to a crash "
+                       "so it is recommended to destroy the control "
+                       "at idle time instead.");
+    }
+
     DoSelectProperty(NULL, wxPG_SEL_NOVALIDATE|wxPG_SEL_DONT_SEND_EVENT);
 
     // This should do prevent things from going too badly wrong
@@ -4365,8 +4383,12 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p,
         evt.SetCanVeto(true);
     }
 
+    m_processedEvent = &evt;
+
     wxEvtHandler* evtHandler = m_eventObject->GetEventHandler();
 
+    m_processedEvent = NULL;
+
     evtHandler->ProcessEvent(evt);
 
     return evt.WasVetoed();