From a4e95c500fd9bdbfa5d3eecfa6b1a99a2c65b768 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 14 Jul 2025 20:09:17 -0700 Subject: [PATCH] Prevent command line applications handling dark mode Double-check before getting background color from invalid m_parent also Fixes https://gitlab.com/kicad/code/kicad/-/issues/21317 (cherry picked from commit 9cb3a37b6f97b58fc1b29411bdc5a55d34603aee) --- common/widgets/grid_color_swatch_helpers.cpp | 2 +- pcbnew/pcb_base_edit_frame.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/common/widgets/grid_color_swatch_helpers.cpp b/common/widgets/grid_color_swatch_helpers.cpp index e683187eda..344493a3be 100644 --- a/common/widgets/grid_color_swatch_helpers.cpp +++ b/common/widgets/grid_color_swatch_helpers.cpp @@ -116,7 +116,7 @@ void GRID_CELL_COLOR_RENDERER::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr, wxDC& void GRID_CELL_COLOR_RENDERER::OnDarkModeToggle() { - m_checkerboardBg = m_parent->GetBackgroundColour(); + m_checkerboardBg = m_parent ? m_parent->GetBackgroundColour() : wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ); } diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 04704fe7b3..b07d5ab932 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -60,6 +60,10 @@ PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, { m_darkMode = KIPLATFORM::UI::IsDarkTheme(); + // Do not register the idle event handler if we are running in headless mode. + if( !wxApp::GetGUIInstance() ) + return; + Bind( wxEVT_IDLE, [this]( wxIdleEvent& aEvent ) {