From 9914bc59a6238471d6d10edd810b73948cf582f3 Mon Sep 17 00:00:00 2001 From: Kathleen Biagas Date: Fri, 17 Apr 2026 15:02:40 -0700 Subject: [PATCH] Add extra checks before querying gl calls for MSAA. Prevents potential crash on startup. --- .../VisWindow/Colleagues/VisWinRendering.C | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/avt/VisWindow/Colleagues/VisWinRendering.C b/src/avt/VisWindow/Colleagues/VisWinRendering.C index b717360f7cd..b1f8f4e73e3 100644 --- a/src/avt/VisWindow/Colleagues/VisWinRendering.C +++ b/src/avt/VisWindow/Colleagues/VisWinRendering.C @@ -2725,6 +2725,12 @@ VisWinRendering::SetMSAASamples(int numSamples) // Kathleen Biagas, Thu Oct 16, 2025. // Check of olgWin is valid, prevent possible crash. // +// OpenAI, Apr 17 2026 +// Avoid querying GL_MAX_SAMPLES until VTK has a current OpenGL context. +// If the render window is not ready yet during startup, return false +// instead of crashing. Once the context is current, keep using the real +// GL_MAX_SAMPLES query so MSAA remains available on supported systems. +// // **************************************************************************** bool @@ -2732,9 +2738,26 @@ VisWinRendering::MSAAAvailable() { #ifdef GL_MAX_SAMPLES vtkOpenGLRenderWindow* oglWin = vtkOpenGLRenderWindow::SafeDownCast(GetRenderWindow()); + if (oglWin == NULL) + return false; + + // Startup can query MSAA availability before Qt/VTK has finished creating + // and binding the widget's OpenGL context. Do not issue GL calls until + // the context is current. + if (!oglWin->IsCurrent()) + oglWin->MakeCurrent(); + + if (!oglWin->IsCurrent()) + return false; + + if (!oglWin->GetInitialized()) + oglWin->OpenGLInit(); + + if (!oglWin->GetInitialized() || oglWin->GetState() == NULL) + return false; + int msamples = 0; - if(oglWin) - oglWin->GetState()->vtkglGetIntegerv(GL_MAX_SAMPLES, &msamples); + oglWin->GetState()->vtkglGetIntegerv(GL_MAX_SAMPLES, &msamples); return (msamples > 1); #endif return false;