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 ) )
|
if( principalSymbol->IsAnnotated( &principalPath ) )
|
||||||
principalRef = principalSymbol->GetRef( &principalPath, false );
|
principalRef = principalSymbol->GetRef( &principalPath, false );
|
||||||
|
|
||||||
|
std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > otherUnits;
|
||||||
|
|
||||||
for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
|
for( const SCH_SHEET_PATH& path : Schematic().GetSheets() )
|
||||||
{
|
{
|
||||||
for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
|
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
|
if( candidateSymbol == principalSymbol
|
||||||
|| ( candidateSymbol->IsAnnotated( &path )
|
|| ( candidateSymbol->IsAnnotated( &path )
|
||||||
&& candidateSymbol->GetRef( &path, false ) == principalRef ) )
|
&& 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
|
// This needs to be done before the LIB_SYMBOL is changed to prevent stale
|
||||||
// library symbols in the schematic file.
|
// library symbols in the schematic file.
|
||||||
path.LastScreen()->Remove( candidateSymbol );
|
path.LastScreen()->Remove( otherUnit );
|
||||||
|
|
||||||
if( !candidateSymbol->IsNew() )
|
if( !otherUnit->IsNew() )
|
||||||
{
|
{
|
||||||
SaveCopyInUndoList( path.LastScreen(), candidateSymbol,
|
SaveCopyInUndoList( path.LastScreen(), otherUnit, UNDO_REDO::CHANGED, appendToUndo );
|
||||||
UNDO_REDO::CHANGED, appendToUndo );
|
|
||||||
appendToUndo = true;
|
appendToUndo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
candidateSymbol->SetLibSymbol( aSymbol.Flatten().release() );
|
otherUnit->SetLibSymbol( aSymbol.Flatten().release() );
|
||||||
candidateSymbol->UpdateFields( &GetCurrentSheet(),
|
otherUnit->UpdateFields( &GetCurrentSheet(),
|
||||||
true, /* update style */
|
true, /* update style */
|
||||||
true, /* update ref */
|
true, /* update ref */
|
||||||
true, /* update other fields */
|
true, /* update other fields */
|
||||||
false, /* reset ref */
|
false, /* reset ref */
|
||||||
false /* reset other fields */ );
|
false /* reset other fields */ );
|
||||||
|
|
||||||
path.LastScreen()->Append( candidateSymbol );
|
path.LastScreen()->Append( otherUnit );
|
||||||
GetCanvas()->GetView()->Update( candidateSymbol );
|
GetCanvas()->GetView()->Update( otherUnit );
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GetCanvas()->Refresh();
|
GetCanvas()->Refresh();
|
||||||
|
|
Loading…
Reference in New Issue