From 6ed8fa0fae68870693fa093fb2aa6a9d57978e53 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 16 Mar 2026 10:46:08 -0700 Subject: [PATCH] Fix crash when realizing instance of OpenGL The FOOTPRINT_PREVIEW_PANEL may instantiate prior to any other checks, we need to ensure that this widget is realized on Linux prior to getting the OpenGL calls otherwise GTKGetDrawingWindow may return NULL incorrectly --- common/gal/opengl/opengl_gal.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index b61e5926ce..ccf967a60a 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -43,6 +43,7 @@ #include #include +#include #include #include @@ -498,6 +499,13 @@ wxString OPENGL_GAL::CheckFeatures( GAL_DISPLAY_OPTIONS& aOptions ) testFrame->Raise(); testFrame->Show(); +#ifdef __WXGTK__ + // On GTK, Show() only queues realization. The GDK drawing window + // needed by SetCurrent() may not exist yet. Yield to let the event + // loop process the realize signal before we try to lock the context. + wxYield(); +#endif + GAL_CONTEXT_LOCKER lock( opengl_gal ); opengl_gal->init(); } @@ -2837,8 +2845,14 @@ void OPENGL_GAL::init() if( glVersion == 0 ) throw std::runtime_error( "Failed to load OpenGL via loader" ); - SetOpenGLInfo( (const char*) glGetString( GL_VENDOR ), (const char*) glGetString( GL_RENDERER ), - (const char*) glGetString( GL_VERSION ) ); + const char* vendor = (const char*) glGetString( GL_VENDOR ); + const char* renderer = (const char*) glGetString( GL_RENDERER ); + const char* version = (const char*) glGetString( GL_VERSION ); + + if( !version ) + throw std::runtime_error( "No GL context is current (glGetString returned NULL)" ); + + SetOpenGLInfo( vendor, renderer, version ); // Check the OpenGL version (minimum 2.1 is required) if( !GLAD_GL_VERSION_2_1 )