Don't deselected items that have been deleted.

De-referencing freed memory is never a good idea.

Fixes: lp:1795195
* https://bugs.launchpad.net/kicad/+bug/1795195
This commit is contained in:
Jeff Young 2018-09-30 11:36:18 +01:00
parent 59723ce3ab
commit 13a41f11eb
1 changed files with 13 additions and 15 deletions

View File

@ -61,12 +61,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
{
// Objects potentially interested in changes:
PICKED_ITEMS_LIST undoList;
KIGFX::VIEW* view = m_toolMgr->GetView();
BOARD* board = (BOARD*) m_toolMgr->GetModel();
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame();
auto connectivity = board->GetConnectivity();
std::set<EDA_ITEM*> savedModules;
std::vector<BOARD_ITEM*> itemsToRemove;
KIGFX::VIEW* view = m_toolMgr->GetView();
BOARD* board = (BOARD*) m_toolMgr->GetModel();
PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) m_toolMgr->GetEditFrame();
auto connectivity = board->GetConnectivity();
std::set<EDA_ITEM*> savedModules;
std::vector<BOARD_ITEM*> itemsToDeselect;
if( Empty() )
return;
@ -142,11 +142,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
case CHT_REMOVE:
{
if( !m_editModules && aCreateUndoEntry )
{
undoList.PushItem( ITEM_PICKER( boardItem, UR_DELETED ) );
}
itemsToRemove.push_back( boardItem );
switch( boardItem->Type() )
{
@ -213,6 +209,8 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
case PCB_MARKER_T: // a marker used to show something
case PCB_SEGZONE_T: // SEG_ZONE items are now deprecated
case PCB_ZONE_AREA_T:
itemsToDeselect.push_back( boardItem );
view->Remove( boardItem );
if( !( changeFlags & CHT_DONE ) )
@ -274,11 +272,11 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a
}
}
// Removing an item should trigger the unselect action
// but only after all items are removed otherwise we can get
// flickering depending on the system
if( itemsToRemove.size() > 0 )
m_toolMgr->RunAction( PCB_ACTIONS::unselectItems, true, &itemsToRemove );
// Removing an item should trigger the unselect action
// but only after all items are removed otherwise we can get
// flickering depending on the system
if( itemsToDeselect.size() > 0 )
m_toolMgr->RunAction( PCB_ACTIONS::unselectItems, true, &itemsToDeselect );
if( !m_editModules && aCreateUndoEntry )
frame->SaveCopyInUndoList( undoList, UR_UNSPECIFIED );