Skip to content

Commit

Permalink
Headless: Prevent crash on errors in graphics init.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Dec 24, 2022
1 parent 808f47f commit f6c26ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Common/GPU/OpenGL/GLFeatures.cpp
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions headless/SDLHeadlessHost.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit f6c26ec

Please sign in to comment.