From 9437afef0bc36d67db3d39870feb02d3eaeb3c03 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 19 Aug 2020 17:17:52 -0400 Subject: [PATCH] Don't try to set an active layer that doesn't exist Fixes https://gitlab.com/kicad/code/kicad/-/issues/5273 --- pcbnew/widgets/appearance_controls.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index 4762751381..bb5f5e2bcd 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -1653,10 +1653,17 @@ void APPEARANCE_CONTROLS::doApplyLayerPreset( const LAYER_PRESET& aPreset ) // If the preset doesn't have an explicit active layer to restore, we can at least // force the active layer to be something in the preset's layer set + PCB_LAYER_ID activeLayer = UNSELECTED_LAYER; + if( aPreset.activeLayer != UNSELECTED_LAYER ) - m_frame->SetActiveLayer( aPreset.activeLayer ); + activeLayer = aPreset.activeLayer; else if( aPreset.layers.any() && !aPreset.layers.test( m_frame->GetActiveLayer() ) ) - m_frame->SetActiveLayer( *aPreset.layers.Seq().begin() ); + activeLayer = *aPreset.layers.Seq().begin(); + + LSET boardLayers = board->GetLayerSet(); + + if( activeLayer != UNSELECTED_LAYER && boardLayers.Contains( activeLayer ) ) + m_frame->SetActiveLayer( activeLayer ); m_frame->GetCanvas()->SyncLayersVisibility( board ); m_frame->GetCanvas()->Refresh();