From ae77dfc45550a3f66c28453ac1e22a123df3f199 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 28 Oct 2020 10:44:18 +0000 Subject: [PATCH] Fix crash bug in marker deletion. --- common/rc_item.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/common/rc_item.cpp b/common/rc_item.cpp index 86fcc3ac1e..4ceaf24de7 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -469,23 +469,26 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo found = true; - wxDataViewItem markerItem = ToItem( m_tree[i] ); - wxDataViewItemArray childItems; - wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent ); - - for( RC_TREE_NODE* child : m_tree[i]->m_Children ) + if( i < (int) m_tree.size() ) // Careful; tree is truncated for large datasets { - childItems.push_back( ToItem( child ) ); - delete child; + wxDataViewItem markerItem = ToItem( m_tree[i] ); + wxDataViewItemArray childItems; + wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent ); + + for( RC_TREE_NODE* child : m_tree[i]->m_Children ) + { + childItems.push_back( ToItem( child ) ); + delete child; + } + + m_tree[i]->m_Children.clear(); + ItemsDeleted( markerItem, childItems ); + + delete m_tree[i]; + m_tree.erase( m_tree.begin() + i ); + ItemDeleted( parentItem, markerItem ); } - m_tree[i]->m_Children.clear(); - ItemsDeleted( markerItem, childItems ); - - delete m_tree[i]; - m_tree.erase( m_tree.begin() + i ); - ItemDeleted( parentItem, markerItem ); - // Only deep delete the current item here; others will be done through the // DeleteAllItems() call below, which is more efficient. m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );