Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
Subject: [PATCH] video: egl: check eglBindAPI return value
Subject: [PATCH] video: egl: fall back to GLES when desktop GL eglBindAPI fails

eglBindAPI(EGL_OPENGL_API) can fail on GLES-only drivers (e.g. libmali)
that do not support desktop OpenGL. Without checking the return value,
SDL proceeds to create what it thinks is a desktop GL context (but is
actually GLES), then crashes when calling desktop GL functions on it.
eglBindAPI(EGL_OPENGL_API) fails on GLES-only drivers (e.g. libmali)
that do not support desktop OpenGL. Rather than returning NULL (which
breaks SDL 1.2 ports using gl4es through box86 → SDL2-compat → SDL3),
fall back to EGL_OPENGL_ES_API so the context can still be created.

Check the return value and fail early so the renderer fallback logic can
try the next backend (opengles2).
gl4es translates desktop GL calls into GLES internally, so an ES EGL
context is correct on these devices.

---
src/video/SDL_egl.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
src/video/SDL_egl.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -746,7 +746,10 @@
@@ -746,7 +746,15 @@
} else {
_this->egl_data->apitype = EGL_OPENGL_API;
}
- _this->egl_data->eglBindAPI(_this->egl_data->apitype);
+ if (!_this->egl_data->eglBindAPI(_this->egl_data->apitype)) {
+ SDL_SetError("Could not bind EGL API");
+ return NULL;
+ /* GLES-only driver (e.g. libmali): desktop GL unavailable.
+ * Fall back to GLES so gl4es / ES-native apps still work. */
+ _this->egl_data->apitype = EGL_OPENGL_ES_API;
+ if (!_this->egl_data->eglBindAPI(_this->egl_data->apitype)) {
+ SDL_SetError("Could not bind EGL API (tried GL and GLES)");
+ return NULL;
+ }
+ }

egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
_this->egl_data->egl_config,