From d6e23dd99b6fae90777875091517924a27d44935 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Tue, 4 Nov 2014 19:23:01 +0000 Subject: [PATCH] Do not mark selected wxPG property as 'being deleted'. Only unselected wxPG property can be marked as 'being deleted'. If this is done for selected wxGP property then in some circumstances it cannot be unselected and hence cannot be safely deleted. See #16617. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78091 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/propgrid/propgridpagestate.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index 541f785a24..82ba97c640 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -1914,6 +1914,7 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) wxPropertyGrid* pg = GetGrid(); + // Try to unselect property and its subproperties. if ( DoIsPropertySelected(item) ) { if ( pg && pg->GetState() == this ) @@ -1933,10 +1934,6 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) wxPG_SEL_DELETING|wxPG_SEL_NOVALIDATE); } - // Prevent property and its children from being re-selected - item->SetFlag(wxPG_PROP_BEING_DELETED); - DoMarkChildrenAsDeleted(item, true); - // Must defer deletion? Yes, if handling a wxPG event. if ( pg && pg->m_processedEvent ) { @@ -1970,6 +1967,15 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete ) return; } + // Property has to be unselected prior deleting. + // Otherwise crash can happen. + wxASSERT_MSG( !DoIsPropertySelected(item) && !item->IsChildSelected(true), + wxT("Failed to unselect deleted property") ); + + // Prevent property and its children from being re-selected + item->SetFlag(wxPG_PROP_BEING_DELETED); + DoMarkChildrenAsDeleted(item, true); + unsigned int indinparent = item->GetIndexInParent(); wxPGProperty* pwc = (wxPGProperty*)item;