From: Jaakko Salli Date: Thu, 10 Sep 2009 14:15:32 +0000 (+0000) Subject: Notify if the grid is being destroyed in an event generated by it X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e84e5ba3c1317779378a3ef2b2dc4657113e6a42 Notify if the grid is being destroyed in an event generated by it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61875 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index 40350413b3..da4d269e1d 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -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; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index fedc84a7c0..963279ad36 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -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();