From cdcf875ec03546d96326d25710dfdf8a8cc07ca3 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 14 Dec 2022 17:47:20 +0100 Subject: [PATCH] sim_model: Fix another not handled exception that fully freeze Eeschema. Can happens with schematics with old sim parameter syntax. Fix also another crash in sim_model. --- eeschema/sim/sim_model.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index 029364753e..8aa3dba81c 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -492,7 +492,15 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL& aBaseModel, unsig { std::unique_ptr model = Create( aBaseModel.GetType() ); - model->SetBaseModel( aBaseModel ); + try + { + model->SetBaseModel( aBaseModel ); + } + catch( IO_ERROR& err ) + { + DisplayErrorMessage( nullptr, err.What() ); + } + model->ReadDataFields( aSymbolPinCount, static_cast*>( nullptr ) ); return model; } @@ -510,7 +518,14 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL& aBaseModel, unsig std::unique_ptr model = Create( type ); - model->SetBaseModel( aBaseModel ); + try + { + model->SetBaseModel( aBaseModel ); + } + catch( IO_ERROR& err ) + { + DisplayErrorMessage( nullptr, err.What() ); + } model->ReadDataFields( aSymbolPinCount, &aFields ); return model; } @@ -1306,7 +1321,13 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject ) aSymbol.AddField( paramsField ); if( modelFromValueField ) - valueField->SetText( wxT( "${SIM.PARAMS}" ) ); + { + // Get the current Value field, after previous changes. + valueField = aSymbol.FindField( wxT( "Value" ) ); + + if( valueField ) + valueField->SetText( wxT( "${SIM.PARAMS}" ) ); + } } if( !pinMap.IsEmpty() )