Iterator safety.
Fixes https://gitlab.com/kicad/code/kicad/issues/13341
This commit is contained in:
parent
e8114dc49a
commit
fc346ea794
|
@ -1782,6 +1782,8 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
|
|||
if( principalSymbol->IsAnnotated( &principalPath ) )
|
||||
principalRef = principalSymbol->GetRef( &principalPath, false );
|
||||
|
||||
std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > otherUnits;
|
||||
|
||||
for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
|
||||
{
|
||||
for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
||||
|
@ -1791,30 +1793,34 @@ void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_SYMBOL& aSymbol,
|
|||
if( candidateSymbol == principalSymbol
|
||||
|| ( candidateSymbol->IsAnnotated( &path )
|
||||
&& candidateSymbol->GetRef( &path, false ) == principalRef ) )
|
||||
{
|
||||
otherUnits.emplace_back( candidateSymbol, path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( auto& [ otherUnit, path ] : otherUnits )
|
||||
{
|
||||
// This needs to be done before the LIB_SYMBOL is changed to prevent stale
|
||||
// library symbols in the schematic file.
|
||||
path.LastScreen()->Remove( candidateSymbol );
|
||||
path.LastScreen()->Remove( otherUnit );
|
||||
|
||||
if( !candidateSymbol->IsNew() )
|
||||
if( !otherUnit->IsNew() )
|
||||
{
|
||||
SaveCopyInUndoList( path.LastScreen(), candidateSymbol,
|
||||
UNDO_REDO::CHANGED, appendToUndo );
|
||||
SaveCopyInUndoList( path.LastScreen(), otherUnit, UNDO_REDO::CHANGED, appendToUndo );
|
||||
appendToUndo = true;
|
||||
}
|
||||
|
||||
candidateSymbol->SetLibSymbol( aSymbol.Flatten().release() );
|
||||
candidateSymbol->UpdateFields( &GetCurrentSheet(),
|
||||
otherUnit->SetLibSymbol( aSymbol.Flatten().release() );
|
||||
otherUnit->UpdateFields( &GetCurrentSheet(),
|
||||
true, /* update style */
|
||||
true, /* update ref */
|
||||
true, /* update other fields */
|
||||
false, /* reset ref */
|
||||
false /* reset other fields */ );
|
||||
|
||||
path.LastScreen()->Append( candidateSymbol );
|
||||
GetCanvas()->GetView()->Update( candidateSymbol );
|
||||
}
|
||||
}
|
||||
path.LastScreen()->Append( otherUnit );
|
||||
GetCanvas()->GetView()->Update( otherUnit );
|
||||
}
|
||||
|
||||
GetCanvas()->Refresh();
|
||||
|
|
Loading…
Reference in New Issue