Some defensive code which may prevent a freed-memory-access.
Fixes https://gitlab.com/kicad/code/kicad/issues/5747
This commit is contained in:
parent
e0ee420cb6
commit
ac4978cf8a
|
@ -432,18 +432,32 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lastGood = -1;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
if( m_view )
|
||||||
|
m_view->UnselectAll();
|
||||||
|
|
||||||
for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
|
for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
|
||||||
{
|
{
|
||||||
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
|
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
|
||||||
MARKER_BASE* marker = rcItem->GetParent();
|
MARKER_BASE* marker = rcItem->GetParent();
|
||||||
bool excluded = marker ? marker->IsExcluded() : false;
|
bool excluded = marker ? marker->IsExcluded() : false;
|
||||||
|
|
||||||
if( aCurrentOnly && rcItem != current_item )
|
if( aCurrentOnly && rcItem != current_item )
|
||||||
|
{
|
||||||
|
if( found && lastGood >= 0 )
|
||||||
|
break;
|
||||||
|
|
||||||
|
lastGood = i;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if( excluded && !aIncludeExclusions )
|
if( excluded && !aIncludeExclusions )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
found = true;
|
||||||
|
|
||||||
wxDataViewItem markerItem = ToItem( m_tree[i] );
|
wxDataViewItem markerItem = ToItem( m_tree[i] );
|
||||||
wxDataViewItemArray childItems;
|
wxDataViewItemArray childItems;
|
||||||
wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
|
wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
|
||||||
|
@ -466,6 +480,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
|
||||||
m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
|
m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( m_view && aCurrentOnly && lastGood >= 0 )
|
||||||
|
m_view->Select( ToItem( m_tree[ lastGood ] ) );
|
||||||
|
|
||||||
if( !aCurrentOnly )
|
if( !aCurrentOnly )
|
||||||
{
|
{
|
||||||
m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
|
m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );
|
||||||
|
|
Loading…
Reference in New Issue