From 5f7ac58f95178278a530a7be521f9ed39c24cbf7 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 6 May 2022 09:47:06 -0700 Subject: [PATCH] Catch errors when saving individual symbols Fixes https://gitlab.com/kicad/code/kicad/issues/11566 (cherry picked from commit f4d4f238764b7a049730640840f0ac21a241b15c) --- .../symbol_editor/symbol_library_manager.cpp | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index 7117e5bcb0..a239f61abc 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -225,30 +225,38 @@ bool SYMBOL_LIBRARY_MANAGER::SaveLibrary( const wxString& aLibrary, const wxStri { LIB_SYMBOL* newSymbol; - if( symbol->IsAlias() ) + try { - std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock(); - - wxCHECK_MSG( oldParent, false, - wxString::Format( "Derived symbol '%s' found with undefined parent.", - symbol->GetName() ) ); - - LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(), - &properties ); - - if( !libParent ) + if( symbol->IsAlias() ) { - libParent = new LIB_SYMBOL( *oldParent.get() ); - pi->SaveSymbol( aLibrary, libParent, &properties ); - } + std::shared_ptr< LIB_SYMBOL > oldParent = symbol->GetParent().lock(); - newSymbol = new LIB_SYMBOL( *symbol ); - newSymbol->SetParent( libParent ); - pi->SaveSymbol( aLibrary, newSymbol, &properties ); + wxCHECK_MSG( oldParent, false, + wxString::Format( wxT( "Derived symbol '%s' found with undefined parent." ), + symbol->GetName() ) ); + + LIB_SYMBOL* libParent = pi->LoadSymbol( aLibrary, oldParent->GetName(), + &properties ); + + if( !libParent ) + { + libParent = new LIB_SYMBOL( *oldParent.get() ); + pi->SaveSymbol( aLibrary, libParent, &properties ); + } + + newSymbol = new LIB_SYMBOL( *symbol ); + newSymbol->SetParent( libParent ); + pi->SaveSymbol( aLibrary, newSymbol, &properties ); + } + else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) ) + { + pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties ); + } } - else if( !pi->LoadSymbol( aLibrary, symbol->GetName(), &properties ) ) + catch( ... ) { - pi->SaveSymbol( aLibrary, new LIB_SYMBOL( *symbol ), &properties ); + res = false; + break; } } }