From 23b7bdef876b189039b7ef97b78a432e670f8007 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 20 Nov 2021 14:11:30 -0500
Subject: [PATCH] offscreen: Don't fail to create a window because of
driver_loaded politics.
Fixes #4922.
---
src/video/SDL_egl.c | 2 +-
src/video/offscreen/SDL_offscreenopengl.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 928a1df2fe7..f9cdcda0a24 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -566,7 +566,7 @@ SDL_EGL_InitializeOffscreen(_THIS, int device)
EGLint num_egl_devices = 0;
const char *egl_device_hint;
- if (_this->gl_config.driver_loaded != 1) {
+ if (_this->gl_config.driver_loaded <= 0) {
return SDL_SetError("SDL_EGL_LoadLibraryOnly() has not been called or has failed.");
}
diff --git a/src/video/offscreen/SDL_offscreenopengl.c b/src/video/offscreen/SDL_offscreenopengl.c
index 45a09e2bfcb..28d4b5f6b8c 100644
--- a/src/video/offscreen/SDL_offscreenopengl.c
+++ b/src/video/offscreen/SDL_offscreenopengl.c
@@ -66,7 +66,13 @@ OFFSCREEN_GL_LoadLibrary(_THIS, const char* path)
return ret;
}
+ /* driver_loaded gets incremented by SDL_GL_LoadLibrary when we return,
+ but SDL_EGL_InitializeOffscreen checks that we're loaded before then,
+ so temporarily bump it since we know that LoadLibraryOnly succeeded. */
+
+ _this->gl_config.driver_loaded++;
ret = SDL_EGL_InitializeOffscreen(_this, 0);
+ _this->gl_config.driver_loaded--;
if (ret != 0) {
return ret;
}