From e3cc0a5bc7a3f3765c67b376207baf6b3067aebd Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 21 Nov 2022 13:28:51 -0800 Subject: [PATCH] Prevent crashes when pasting symbols When pasting a symbol that originates in a non-standard library, the symbol may _only_ have an instance in the sheet and so adding it to the sheet updates the instance data and needs to be refreshed before annotating --- eeschema/tools/sch_editor_control.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 4aece585e5..8a5b95e3ed 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -2086,6 +2086,27 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pasteMode == PASTE_MODE::RESPECT_OPTIONS ) { + pastedSymbols.clear(); + + // The symbol references may be changed by adding them to the schematic + // if they only exist on the schematic (e.g. from non-standard libraries), so + // recreate the pastedSymbols reference list here with the current data + for( unsigned i = 0; i < loadedItems.size(); ++i ) + { + if( SCH_SYMBOL* symbol = dyn_cast( loadedItems[i] ) ) + { + for( SCH_SHEET_PATH& instance : pasteInstances ) + { + // Ignore pseudo-symbols (e.g. power symbols) + if( symbol->GetRef( &instance )[0] != wxT( '#' ) ) + { + SCH_REFERENCE schReference( symbol, symbol->GetLibSymbolRef().get(), instance ); + pastedSymbols[instance].AddItem( schReference ); + } + } + } + } + for( SCH_SHEET_PATH& instance : pasteInstances ) { pastedSymbols[instance].SortByReferenceOnly();