SDL_EGL_ChooseConfig: don't fall through if no matching format exists On Raspberry Pi 3 via the VC4 driver in firmware KMS mode, none of the found configs match the desired format, causing the function to fall through without any config being selected. Fix by first iterating over the found configs, and if no match exists, don't exclude the non-matching configs. This should fix RPI3 and possibly other targets without breaking targets that have a matching native format (such as RPI4).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 1561bc9..cb19a28 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -683,6 +683,7 @@ SDL_EGL_ChooseConfig(_THIS)
EGLint found_configs = 0, value;
/* 128 seems even nicer here */
EGLConfig configs[128];
+ SDL_bool has_matching_format = SDL_FALSE;
int i, j, best_bitdiff = -1, bitdiff;
if (!_this->egl_data) {
@@ -766,11 +767,24 @@ SDL_EGL_ChooseConfig(_THIS)
return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
}
+ /* first ensure that a found config has a matching format, or the function will fall through. */
+ for (i = 0; i < found_configs; i++ ) {
+ if (_this->egl_data->egl_required_visual_id)
+ {
+ EGLint format;
+ _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
+ configs[i],
+ EGL_NATIVE_VISUAL_ID, &format);
+ if (_this->egl_data->egl_required_visual_id == format)
+ has_matching_format = SDL_TRUE;
+ }
+ }
+
/* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
for (i = 0; i < found_configs; i++ ) {
- if (_this->egl_data->egl_required_visual_id)
+ if (has_matching_format && _this->egl_data->egl_required_visual_id)
{
EGLint format;
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,