From 20b1314fc852fd378dcd82cbc2eb1bfa1af17fef Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Wed, 13 May 2026 12:00:58 -0400 Subject: [PATCH] Fix status bar field position assertion when opening page layout editor. Our KISTATUSBAR object was making the invalid assumption that all of the optional panes were available. This is not the case with the page layout editor which caused assertions in the wxStatusBar code when attempting to get status bar pane information that was not in the status bar. Add checks to ensure we don't attempt to access invalid pane ordinals. Fixes KICAD-10XP --- common/widgets/kistatusbar.cpp | 98 ++++++++++++++++----------- pagelayout_editor/pl_editor_frame.cpp | 7 +- 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/common/widgets/kistatusbar.cpp b/common/widgets/kistatusbar.cpp index 55cdd32094..9a387c085f 100644 --- a/common/widgets/kistatusbar.cpp +++ b/common/widgets/kistatusbar.cpp @@ -227,56 +227,76 @@ void KISTATUSBAR::layoutControls() constexpr int padding = 5; wxRect r; - GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL ), r ); - int x = r.GetLeft(); - int y = r.GetTop(); - int textHeight = KIUI::GetTextSize( wxT( "bp" ), this ).y; + int sbField = m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL ); - if( r.GetHeight() > textHeight ) - y += ( r.GetHeight() - textHeight ) / 2; - - m_backgroundTxt->SetPosition( { x, y } ); - m_backgroundTxt->SetSize( r.GetWidth(), textHeight ); - updateBackgroundText(); + if( sbField >= 0 && sbField < GetFieldsCount() ) + { + GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_LABEL ), r ); + int x = r.GetLeft(); + int y = r.GetTop(); + int textHeight = KIUI::GetTextSize( wxT( "bp" ), this ).y; - GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE ), r ); - x = r.GetLeft(); - y = r.GetTop(); - int w = r.GetWidth(); - int h = r.GetHeight(); - wxSize buttonSize( 0, 0 ); + if( r.GetHeight() > textHeight ) + y += ( r.GetHeight() - textHeight ) / 2; - if( m_backgroundStopButton ) - { - buttonSize = m_backgroundStopButton->GetEffectiveMinSize(); - m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } ); - m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h ); - buttonSize.x += padding; + m_backgroundTxt->SetPosition( { x, y } ); + m_backgroundTxt->SetSize( r.GetWidth(), textHeight ); + updateBackgroundText(); } - m_backgroundProgressBar->SetPosition( { x + padding, y } ); - m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - padding, h ); + sbField = m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE ); - if( m_notificationsButton ) + if( sbField >= 0 && sbField < GetFieldsCount() ) { - GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION ), r ); - x = r.GetLeft(); - y = r.GetTop(); - h = r.GetHeight(); - buttonSize = m_notificationsButton->GetEffectiveMinSize(); - m_notificationsButton->SetPosition( { x, y } ); - m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h ); + GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::BGJOB_GAUGE ), r ); + int x = r.GetLeft(); + int y = r.GetTop(); + int w = r.GetWidth(); + int h = r.GetHeight(); + wxSize buttonSize( 0, 0 ); + + if( m_backgroundStopButton ) + { + buttonSize = m_backgroundStopButton->GetEffectiveMinSize(); + m_backgroundStopButton->SetPosition( { x + w - buttonSize.GetWidth(), y } ); + m_backgroundStopButton->SetSize( buttonSize.GetWidth(), h ); + buttonSize.x += padding; + } + + m_backgroundProgressBar->SetPosition( { x + padding, y } ); + m_backgroundProgressBar->SetSize( w - buttonSize.GetWidth() - padding, h ); + + if( m_notificationsButton ) + { + sbField = m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION ); + + if( sbField >= 0 && sbField < GetFieldsCount() ) + { + GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::NOTIFICATION ), r ); + x = r.GetLeft(); + y = r.GetTop(); + h = r.GetHeight(); + buttonSize = m_notificationsButton->GetEffectiveMinSize(); + m_notificationsButton->SetPosition( { x, y } ); + m_notificationsButton->SetSize( buttonSize.GetWidth() + 6, h ); + } + } } if( m_warningButton ) { - GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::WARNING ), r ); - x = r.GetLeft(); - y = r.GetTop(); - h = r.GetHeight(); - buttonSize = m_warningButton->GetEffectiveMinSize(); - m_warningButton->SetPosition( { x, y } ); - m_warningButton->SetSize( buttonSize.GetWidth() + 6, h ); + sbField = m_normalFieldsCount + *fieldIndex( FIELD::WARNING ); + + if( sbField >= 0 && sbField < GetFieldsCount() ) + { + GetFieldRect( m_normalFieldsCount + *fieldIndex( FIELD::WARNING ), r ); + int x = r.GetLeft(); + int y = r.GetTop(); + int h = r.GetHeight(); + wxSize buttonSize = m_warningButton->GetEffectiveMinSize(); + m_warningButton->SetPosition( { x, y } ); + m_warningButton->SetSize( buttonSize.GetWidth() + 6, h ); + } } } diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 28eece6d56..c53eabe2e9 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -144,8 +144,8 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : configureToolbars(); RecreateToolbars(); - wxWindow* stsbar = GetStatusBar(); - int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2; + wxStatusBar* stsbar = GetStatusBar(); + int spacer = KIUI::GetTextSize( wxT( "M" ), stsbar ).x * 2; int dims[] = { @@ -177,7 +177,8 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : KIUI::GetTextSize( _( "Constrain to H, V, 45" ), stsbar ).x + spacer }; - SetStatusWidths( arrayDim( dims ), dims ); + if( stsbar ) + stsbar->SetFieldsCount( arrayDim( dims ), dims ); m_auimgr.SetManagedWindow( this );