Fix incorrect use of iterators.
Iterators always create problems when using them on a list that is modified during iteration.
This commit is contained in:
parent
969209c2cc
commit
1724f902a1
|
@ -160,14 +160,15 @@ void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( PCB_LAYER_ID aLayer )
|
||||||
if( !IsOK( this, msg ) )
|
if( !IsOK( this, msg ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PICKED_ITEMS_LIST pickList;
|
// Step 1: build the list of items to remove.
|
||||||
ITEM_PICKER picker( NULL, UR_DELETED );
|
// because we are using iterators, we cannot modify the drawing list during iterate
|
||||||
BOARD_ITEM* PtNext;
|
// so we are using a 2 steps calculation:
|
||||||
|
// First, collect items.
|
||||||
|
// Second, remove items.
|
||||||
|
std::vector<BOARD_ITEM*> list;
|
||||||
|
|
||||||
for( auto item : GetBoard()->Drawings() )
|
for( auto item : GetBoard()->Drawings() )
|
||||||
{
|
{
|
||||||
PtNext = item->Next();
|
|
||||||
|
|
||||||
switch( item->Type() )
|
switch( item->Type() )
|
||||||
{
|
{
|
||||||
case PCB_LINE_T:
|
case PCB_LINE_T:
|
||||||
|
@ -175,11 +176,7 @@ void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( PCB_LAYER_ID aLayer )
|
||||||
case PCB_DIMENSION_T:
|
case PCB_DIMENSION_T:
|
||||||
case PCB_TARGET_T:
|
case PCB_TARGET_T:
|
||||||
if( item->GetLayer() == aLayer )
|
if( item->GetLayer() == aLayer )
|
||||||
{
|
list.push_back( item );
|
||||||
item->UnLink();
|
|
||||||
picker.SetItem( item );
|
|
||||||
pickList.PushItem( picker );
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -193,12 +190,23 @@ void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( PCB_LAYER_ID aLayer )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( pickList.GetCount() )
|
if( list.size() == 0 ) // No item found
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Step 2: remove items from main list, and move them to the undo list
|
||||||
|
PICKED_ITEMS_LIST pickList;
|
||||||
|
ITEM_PICKER picker( NULL, UR_DELETED );
|
||||||
|
|
||||||
|
for( auto item : list )
|
||||||
{
|
{
|
||||||
|
item->UnLink();
|
||||||
|
picker.SetItem( item );
|
||||||
|
pickList.PushItem( picker );
|
||||||
|
}
|
||||||
|
|
||||||
OnModify();
|
OnModify();
|
||||||
SaveCopyInUndoList(pickList, UR_DELETED);
|
SaveCopyInUndoList(pickList, UR_DELETED);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void Abort_EditEdge( EDA_DRAW_PANEL* aPanel, wxDC* DC )
|
static void Abort_EditEdge( EDA_DRAW_PANEL* aPanel, wxDC* DC )
|
||||||
|
|
Loading…
Reference in New Issue