Delay deletion of the RC_ITEM tree nodes

The wxWidgets call "ItemDeleted" still requires access to the item in
memory, so we delay deletion by storing removed items to the end of the
call

Fixes https://gitlab.com/kicad/code/kicad/issues/6301
This commit is contained in:
Seth Hillbrand 2020-11-23 09:51:30 -08:00
parent 32ec8fa928
commit 298bc13f5d
1 changed files with 8 additions and 2 deletions

View File

@ -433,6 +433,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
const std::shared_ptr<RC_ITEM> current_item = current_node ? current_node->m_RcItem : nullptr;
/// Keep a vector of elements to free after wxWidgets is definitely done accessing them
std::vector<RC_TREE_NODE*> to_delete;
if( aCurrentOnly && !current_item )
{
wxBell();
@ -481,13 +484,13 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
for( RC_TREE_NODE* child : m_tree[i]->m_Children )
{
childItems.push_back( ToItem( child ) );
delete child;
to_delete.push_back( child );
}
m_tree[i]->m_Children.clear();
ItemsDeleted( markerItem, childItems );
delete m_tree[i];
to_delete.push_back( m_tree[i] );
m_tree.erase( m_tree.begin() + i );
ItemDeleted( parentItem, markerItem );
}
@ -500,6 +503,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
if( m_view && aCurrentOnly && lastGood >= 0 )
m_view->Select( ToItem( m_tree[ lastGood ] ) );
for( RC_TREE_NODE* item : to_delete )
delete( item );
if( !aCurrentOnly )
m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );