PANEL_COLOR_SETTINGS: avoid crash if the selected theme is no longer existing.

If a previously selected color theme is no longer existing, switch to the default
theme to build the panel.

Fixes #5032
https://gitlab.com/kicad/code/kicad/issues/5032
This commit is contained in:
jean-pierre charras 2020-08-01 20:23:18 +02:00
parent c8170d9430
commit 1bcc819eed
1 changed files with 9 additions and 0 deletions

View File

@ -198,8 +198,17 @@ void PANEL_COLOR_SETTINGS::createSwatch( int aLayer, const wxString& aName )
{ {
wxStaticText* label = new wxStaticText( m_colorsListWindow, wxID_ANY, aName ); wxStaticText* label = new wxStaticText( m_colorsListWindow, wxID_ANY, aName );
// The previously selected theme can be deleted and cannot be selected.
// so select the default theme (first theme of the list)
if( m_cbTheme->GetSelection() < 0 )
{
m_cbTheme->SetSelection( 0 );
onNewThemeSelected();
}
void* clientData = m_cbTheme->GetClientData( m_cbTheme->GetSelection() ); void* clientData = m_cbTheme->GetClientData( m_cbTheme->GetSelection() );
COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( clientData ); COLOR_SETTINGS* selected = static_cast<COLOR_SETTINGS*>( clientData );
int id = FIRST_BUTTON_ID + aLayer; int id = FIRST_BUTTON_ID + aLayer;
COLOR4D defaultColor = selected->GetDefaultColor( aLayer ); COLOR4D defaultColor = selected->GetDefaultColor( aLayer );
COLOR4D color = m_currentSettings->GetColor( aLayer ); COLOR4D color = m_currentSettings->GetColor( aLayer );