From 0067d1dbef3d5b42f7ae86e52917d1b04a50fc2e Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 31 Dec 2016 13:55:44 +0100 Subject: vo_opengl: egl: handle potential eglChooseConfig failures This is actually a pretty important fix. eglChooseConfig() might be the first thing that fails when porobing for desktop GL / ES2 / ES3 support, because EGL_RENDERABLE_TYPE is set values specific to the underlying APIs. Not sure how the hell this worked before. EGL 1.4 implementations certainly could fail the call with EGL_BAD_ATTRIBUTE if EGL_RENDERABLE_TYPE has EGL_OPENGL_ES3_BIT set. It's quite possible that many EGL implementations tolerate invalid EGLConfig values steming from uininitialized EGLConfig values (and eglCreateWindowSurface() even is specified to return EGL_BAD_CONFIG error code for "not valid" EGLConfigs). --- video/out/opengl/egl_helpers.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'video') diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c index 3d937a57aa..05f594f4e0 100644 --- a/video/out/opengl/egl_helpers.c +++ b/video/out/opengl/egl_helpers.c @@ -70,24 +70,23 @@ static bool create_context(EGLDisplay display, struct mp_log *log, bool probing, EGL_NONE }; - EGLint config_count; - EGLConfig *configs = NULL; + EGLint num_configs; + if (!eglChooseConfig(display, attributes, NULL, 0, &num_configs)) + num_configs = 0; - eglChooseConfig(display, attributes, NULL, 0, &config_count); + EGLConfig *configs = talloc_array(NULL, EGLConfig, num_configs); + if (!eglChooseConfig(display, attributes, configs, num_configs, &num_configs)) + num_configs = 0; - if (config_count) { - configs = talloc_array(NULL, EGLConfig, config_count); - eglChooseConfig(display, attributes, configs, config_count, &config_count); - } - - if (!config_count) { - mp_msg(log, msgl, "Could not find EGL configuration!\n"); + if (!num_configs) { + talloc_free(configs); + mp_msg(log, msgl, "Could not choose EGLConfig!\n"); return false; } int chosen = 0; if (opts->refine_config) - chosen = opts->refine_config(opts->user_data, configs, config_count); + chosen = opts->refine_config(opts->user_data, configs, num_configs); EGLConfig config = configs[chosen]; talloc_free(configs); -- cgit v1.2.3