From f6c26ecac0701d20147c0c3864464046604eb8e9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 24 Dec 2022 17:43:32 +0000 Subject: [PATCH] Headless: Prevent crash on errors in graphics init. --- Common/GPU/OpenGL/GLFeatures.cpp | 4 ++-- headless/SDLHeadlessHost.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Common/GPU/OpenGL/GLFeatures.cpp b/Common/GPU/OpenGL/GLFeatures.cpp index 06ef1ead3bef..c7bd284febfe 100644 --- a/Common/GPU/OpenGL/GLFeatures.cpp +++ b/Common/GPU/OpenGL/GLFeatures.cpp @@ -273,8 +273,8 @@ void CheckGLExtensions() { // Try to load GLES 3.0 only if "3.0" found in version // This simple heuristic avoids issues on older devices where you can only call eglGetProcAddress a limited // number of times. Make sure to check for 3.0 in the shader version too to avoid false positives, see #5584. - bool gl_3_0_in_string = strstr(versionStr, "3.0") && (glslVersionStr && strstr(glslVersionStr, "3.0")); - bool gl_3_1_in_string = strstr(versionStr, "3.1") && (glslVersionStr && strstr(glslVersionStr, "3.1")); // intentionally left out .1 + bool gl_3_0_in_string = versionStr && strstr(versionStr, "3.0") && glslVersionStr && strstr(glslVersionStr, "3.0"); + bool gl_3_1_in_string = versionStr && strstr(versionStr, "3.1") && glslVersionStr && strstr(glslVersionStr, "3.1"); // intentionally left out .1 if ((gl_3_0_in_string || gl_3_1_in_string) && gl3stubInit()) { gl_extensions.ver[0] = 3; if (gl_3_1_in_string) { diff --git a/headless/SDLHeadlessHost.cpp b/headless/SDLHeadlessHost.cpp index af6fc4a99419..516203abe7e6 100644 --- a/headless/SDLHeadlessHost.cpp +++ b/headless/SDLHeadlessHost.cpp @@ -120,7 +120,17 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) { SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); screen_ = CreateHiddenWindow(); + if (!screen_) { + const char *err = SDL_GetError(); + printf("Failed to create offscreen window: %s\n", err ? err : "(unknown error)"); + return false; + } glContext_ = SDL_GL_CreateContext(screen_); + if (!glContext_) { + const char *err = SDL_GetError(); + printf("Failed to create GL context: %s\n", err ? err : "(unknown error)"); + return false; + } // Ensure that the swap interval is set after context creation (needed for kmsdrm) SDL_GL_SetSwapInterval(0);