Commit 03f27a3a75c74dce72f68f940d7e0ca91bf9109a

Sylvain Becker 2019-10-18T13:27:58

Add robustness getting the EGL version (see bug #4040)

diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index ce05646..6420608 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -509,6 +509,18 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
     }
 #endif
 
+    /* Get the EGL version */
+    if (_this->egl_data->eglQueryString && _this->egl_data->egl_version_major == 0 && _this->egl_data->egl_version_major == 0) {
+        const char *egl_version = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_VERSION);
+        int major = 0, minor = 0;
+        if (egl_version != NULL) {
+            if (SDL_sscanf(egl_version, "%d.%d", &major, &minor) == 2) {
+                _this->egl_data->egl_version_major = major;
+                _this->egl_data->egl_version_minor = minor;
+            }
+        }
+    }
+
     _this->egl_data->is_offscreen = 0;
 
     return 0;
@@ -594,6 +606,18 @@ SDL_EGL_InitializeOffscreen(_THIS, int device)
         }
     }
 
+    /* Get the EGL version */
+    if (_this->egl_data->eglQueryString && _this->egl_data->egl_version_major == 0 && _this->egl_data->egl_version_major == 0) {
+        const char *egl_version = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_VERSION);
+        int major = 0, minor = 0;
+        if (egl_version != NULL) {
+            if (SDL_sscanf(egl_version, "%d.%d", &major, &minor) == 2) {
+                _this->egl_data->egl_version_major = major;
+                _this->egl_data->egl_version_minor = minor;
+            }
+        }
+    }
+
     _this->egl_data->is_offscreen = 1;
 
     return 0;