From 87377d1aacdef290d42e1a066be10f67e9347cde Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 18 Jan 2023 13:49:50 +0000 Subject: [PATCH] Stop stepping on user's data. Just because we can't find the file doesn't mean the path to it has no value. Don't delete it. And don't crash afterwards either. Fixes https://gitlab.com/kicad/code/kicad/issues/13578 --- eeschema/dialogs/dialog_sim_model.cpp | 29 ++++++++++++++++----------- eeschema/dialogs/dialog_sim_model.h | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index c7a690766a..2fac451437 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -175,12 +175,12 @@ bool DIALOG_SIM_MODEL::TransferDataToWindow() { // The model is sourced from a library, optionally with instance overrides. m_useLibraryModelRadioButton->SetValue( true ); - loadLibrary( libraryFilename ); - // Must be set before curModel() is used since the latter checks the combobox value. - if( m_modelNameChoice->IsEmpty() ) + if( !loadLibrary( libraryFilename ) ) { + m_libraryPathText->ChangeValue( libraryFilename ); m_modelNameChoice->SetSelection( -1 ); + m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields ); } else { @@ -199,12 +199,14 @@ bool DIALOG_SIM_MODEL::TransferDataToWindow() { m_modelNameChoice->SetSelection( modelIdx ); } + + m_curModelType = curModel().GetType(); } if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) ) { - SIM_MODEL_KIBIS* kibismodel = dynamic_cast( - &m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() ); + int idx = m_modelNameChoice->GetSelection(); + auto kibismodel = dynamic_cast( &m_libraryModelsMgr.GetModels().at( idx ).get() ); if( kibismodel ) { @@ -245,8 +247,6 @@ bool DIALOG_SIM_MODEL::TransferDataToWindow() } } } - - m_curModelType = curModel().GetType(); } else { @@ -310,13 +310,16 @@ bool DIALOG_SIM_MODEL::TransferDataFromWindow() if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() ) return false; - std::string modelName = m_modelNameChoice->GetStringSelection().ToStdString(); + if( !m_modelNameChoice->IsEmpty() ) + { + std::string modelName = m_modelNameChoice->GetStringSelection().ToStdString(); - SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY::NAME_FIELD, modelName ); + SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY::NAME_FIELD, modelName ); + } std::string path; - if( ( library() && m_useLibraryModelRadioButton->GetValue() ) || isIbisLoaded() ) + if( m_useLibraryModelRadioButton->GetValue() || isIbisLoaded() ) { path = m_libraryPathText->GetValue(); wxFileName fn( path ); @@ -676,7 +679,7 @@ void DIALOG_SIM_MODEL::removeOrphanedPinAssignments() template -void DIALOG_SIM_MODEL::loadLibrary( const wxString& aLibraryPath, +bool DIALOG_SIM_MODEL::loadLibrary( const wxString& aLibraryPath, bool aForceReload ) { wxString msg; @@ -688,7 +691,7 @@ void DIALOG_SIM_MODEL::loadLibrary( const wxString& aLibraryP if( reporter.HasMessage() ) { DisplayErrorMessage( this, msg ); - return; + return false; } std::vector sourcePins = m_symbol.GetAllLibPins(); @@ -731,6 +734,8 @@ void DIALOG_SIM_MODEL::loadLibrary( const wxString& aLibraryP m_ibisModelCombobox->SetSelection( -1 ); m_ibisPinCombobox->SetSelection( -1 ); } + + return true; } diff --git a/eeschema/dialogs/dialog_sim_model.h b/eeschema/dialogs/dialog_sim_model.h index ebef451d52..cfe0111431 100644 --- a/eeschema/dialogs/dialog_sim_model.h +++ b/eeschema/dialogs/dialog_sim_model.h @@ -78,7 +78,7 @@ private: void removeOrphanedPinAssignments(); - void loadLibrary( const wxString& aLibraryPath, bool aForceReload = false ); + bool loadLibrary( const wxString& aLibraryPath, bool aForceReload = false ); void addParamPropertyIfRelevant( int aParamIndex ); wxPGProperty* newParamProperty( int aParamIndex ) const;