From 0271047b26d75bb2dfe808ebda7704ae2f757b2b Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 27 Jul 2025 17:22:02 -0700 Subject: [PATCH] Add a method to force KiCad to software rendering There are enough cases of problematic OpenGL implementations to need a way to avoid calling OpenGL in the first place. This provides a temporary method for people experiencing crashing KiCad or starting KiCad over a remote terminal to temporarily enforce software rendering --- common/eda_draw_frame.cpp | 19 +++++++++++++++++++ kicad/kicad.cpp | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index debd608e63..d15525c812 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -944,6 +944,19 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::loadCanvasTypeSetting( APP_SETTING if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ) canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL; + wxString envCanvasType; + + if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", &envCanvasType ) ) + { + if( envCanvasType.CmpNoCase( "1" ) == 0 + || envCanvasType.CmpNoCase( "true" ) == 0 + || envCanvasType.CmpNoCase( "yes" ) == 0 ) + { + // Force software rendering if the environment variable is set + canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; + } + } + return canvasType; } @@ -964,6 +977,12 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas if( !alg::contains( s_allowedFrames, m_ident ) ) return false; + if( wxGetEnv( "KICAD_SOFTWARE_RENDERING", nullptr ) ) + { + // If the environment variable is set, don't save the canvas type. + return false; + } + if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) { diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp index 4ff6a7e78f..dc98263a2a 100644 --- a/kicad/kicad.cpp +++ b/kicad/kicad.cpp @@ -104,6 +104,10 @@ bool PGM_KICAD::OnPgmInit() { wxCMD_LINE_OPTION, "f", "frame", "Frame to load", wxCMD_LINE_VAL_STRING, 0 }, { wxCMD_LINE_SWITCH, "n", "new", "New instance of KiCad, does not attempt to load previously open files", wxCMD_LINE_VAL_NONE, 0 }, +#ifndef __WXOSX__ + { wxCMD_LINE_SWITCH, nullptr, "software-rendering", "Use software rendering instead of OpenGL", + wxCMD_LINE_VAL_NONE, 0 }, +#endif { wxCMD_LINE_PARAM, nullptr, nullptr, "File to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 } @@ -158,6 +162,11 @@ bool PGM_KICAD::OnPgmInit() Kiway.SetCtlBits( KFCTL_STANDALONE ); } + if( parser.Found( "software-rendering" ) ) + { + wxSetEnv( "KICAD_SOFTWARE_RENDERING", "1" ); + } + bool skipPythonInit = false; if( appType == FRAME_BM2CMP || appType == FRAME_PL_EDITOR || appType == FRAME_GERBER