From 80e372b7d97435ee8b5435f3df9dcd50d115a244 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 30 Oct 2021 11:17:10 -0400 Subject: [PATCH] Fix blank DC sources causing crash in dialog creation Fixes https://gitlab.com/kicad/code/kicad/-/issues/9482 --- eeschema/dialogs/dialog_sim_settings.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_settings.cpp b/eeschema/dialogs/dialog_sim_settings.cpp index 517290bad4..1041c2d676 100644 --- a/eeschema/dialogs/dialog_sim_settings.cpp +++ b/eeschema/dialogs/dialog_sim_settings.cpp @@ -395,30 +395,24 @@ void DIALOG_SIM_SETTINGS::updateDCSources( wxChar aType, wxChoice* aSource ) if( !aSource->IsEmpty() ) prevSelection = aSource->GetString( aSource->GetSelection() ); - std::vector sourcesList; - bool enableSrcSelection = true; + std::set sourcesList; + bool enableSrcSelection = true; if( aType != 'T' ) { for( const auto& item : m_exporter->GetSpiceItems() ) { - if( item.m_primitive == aType ) - sourcesList.push_back( item.m_refName ); + if( item.m_primitive == aType && !item.m_refName.IsEmpty() ) + sourcesList.insert( item.m_refName ); } - std::sort( sourcesList.begin(), sourcesList.end(), - [](wxString& a, wxString& b) -> bool - { - return a.Len() < b.Len() || b.Cmp( a ) > 0; - } ); - if( aSource == m_dcSource2 && !m_dcEnable2->IsChecked() ) enableSrcSelection = false; } else { prevSelection = wxT( "TEMP" ); - sourcesList.push_back( prevSelection ); + sourcesList.insert( prevSelection ); enableSrcSelection = false; } @@ -426,7 +420,7 @@ void DIALOG_SIM_SETTINGS::updateDCSources( wxChar aType, wxChoice* aSource ) aSource->Clear(); - for( auto& src : sourcesList ) + for( const wxString& src : sourcesList ) aSource->Append( src ); // Try to restore the previous selection, if possible