From 5ae1b271e77479816fbd67c9701810aeb21aff9b Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 4 Dec 2023 18:12:51 +0100 Subject: [PATCH] Fix crash: Under some circumstances the command "Export symbols to (new) library" produces a crash when the library links are updated, and a power symbol is not found in any loaded library. Add also an option to export all symbols or all not pwer symbols From master branch Fixes #16229 https://gitlab.com/kicad/code/kicad/-/issues/ --- eeschema/sch_screen.cpp | 3 ++- eeschema/tools/sch_editor_control.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 02e5b39325..e91208bd8e 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -1030,7 +1030,8 @@ void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter ) } } - symbol->SetLibSymbol( libSymbol.release() ); + if( libSymbol.get() ) // Only change the old link if the new link exists + symbol->SetLibSymbol( libSymbol.release() ); } // Changing the symbol may adjust the bbox of the symbol. This re-inserts the diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 2624dbcc53..166f6fb0d2 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -332,10 +332,12 @@ void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aF int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) { + bool savePowerSymbols = IsOK( m_frame, _( "Include power symbols in schematic to the library?" ) ); + bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary ); SCH_REFERENCE_LIST symbols; - m_frame->Schematic().GetSheets().GetSymbols( symbols, false ); + m_frame->Schematic().GetSheets().GetSymbols( symbols, savePowerSymbols ); std::map libSymbols; std::map> symbolMap; @@ -430,7 +432,6 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) LIB_ID id = it.first; id.SetLibNickname( targetLib ); - for( SCH_SYMBOL* symbol : symbolMap[it.first] ) { m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED, append, false); @@ -487,6 +488,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent ) for( SCH_SHEET_PATH& sheet : sheets ) { SCH_SCREEN* screen = sheet.LastScreen(); + if( processedScreens.find( ( screen ) ) == processedScreens.end() ) { processedScreens.insert( screen );