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;