From 2bf0eb7eadb3f5ee0ce5b532ecf53cac130d0c86 Mon Sep 17 00:00:00 2001 From: Gess1t <39861216+Mrcubix@users.noreply.github.com> Date: Sun, 27 Oct 2024 09:20:51 +0100 Subject: [PATCH] Handle failure of OpenGL context creation (#2172) --- src/frontend/qt_sdl/Screen.cpp | 12 ++++-------- src/frontend/qt_sdl/Window.cpp | 10 +++++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/frontend/qt_sdl/Screen.cpp b/src/frontend/qt_sdl/Screen.cpp index 11a6150a..ff049120 100644 --- a/src/frontend/qt_sdl/Screen.cpp +++ b/src/frontend/qt_sdl/Screen.cpp @@ -753,10 +753,8 @@ bool ScreenPanelGL::createContext() if (parentwin) { if (windowinfo.has_value()) - { - glContext = parentwin->getOGLContext()->CreateSharedContext(*windowinfo); - glContext->DoneCurrent(); - } + if (glContext = parentwin->getOGLContext()->CreateSharedContext(*windowinfo)) + glContext->DoneCurrent(); } else { @@ -764,10 +762,8 @@ bool ScreenPanelGL::createContext() GL::Context::Version{GL::Context::Profile::Core, 4, 3}, GL::Context::Version{GL::Context::Profile::Core, 3, 2}}; if (windowinfo.has_value()) - { - glContext = GL::Context::Create(*windowinfo, versionsToTry); - glContext->DoneCurrent(); - } + if (glContext = GL::Context::Create(*windowinfo, versionsToTry)) + glContext->DoneCurrent(); } return glContext != nullptr; diff --git a/src/frontend/qt_sdl/Window.cpp b/src/frontend/qt_sdl/Window.cpp index 50472300..3ba9ada5 100644 --- a/src/frontend/qt_sdl/Window.cpp +++ b/src/frontend/qt_sdl/Window.cpp @@ -841,7 +841,15 @@ void MainWindow::createScreenPanel() panel = panelGL; - panelGL->createContext(); + // Check that creating the context hasn't failed + if (panelGL->createContext() == false) + { + Log(LogLevel::Error, "Failed to create OpenGL context, falling back to Software Renderer.\n"); + hasOGL = false; + + globalCfg.SetBool("Screen.UseGL", false); + globalCfg.SetInt("3D.Renderer", renderer3D_Software); + } } if (!hasOGL)