From d15f11a9f7c275d57b2566962f3d9044d2599db5 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 20 Aug 2023 11:09:30 +0200 Subject: [PATCH] context_drm_egl: more correctness fixes for uninit procedure - uninit gl before the VO - destroy EGL surface before context: reverse of the creation order. I also checked other code which doesn't even call this and leaves it up to eglTerminate, which frees everything anyway. But this seems more correct since we're destroying the gbm surface afterwards. - check against at EGL_NO_DISPLAY instead of 0: there is probably no EGL implementation where this makes a difference, it is more correct regardless - remove pointless eglDestroyContext call - check render_fd before close --- video/out/opengl/context_drm_egl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c index b59e8dde81..5414ab75e3 100644 --- a/video/out/opengl/context_drm_egl.c +++ b/video/out/opengl/context_drm_egl.c @@ -485,8 +485,8 @@ static void drm_egl_uninit(struct ra_ctx *ctx) drmModeAtomicFree(atomic_ctx->request); } - vo_drm_uninit(ctx->vo); ra_gl_ctx_uninit(ctx); + vo_drm_uninit(ctx->vo); if (p) { // According to GBM documentation all BO:s must be released @@ -497,18 +497,17 @@ static void drm_egl_uninit(struct ra_ctx *ctx) eglMakeCurrent(p->egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (p->egl.display) { - eglDestroyContext(p->egl.display, p->egl.context); + if (p->egl.display != EGL_NO_DISPLAY) { eglDestroySurface(p->egl.display, p->egl.surface); + eglDestroyContext(p->egl.display, p->egl.context); } if (p->gbm.surface) gbm_surface_destroy(p->gbm.surface); eglTerminate(p->egl.display); gbm_device_destroy(p->gbm.device); - p->egl.context = EGL_NO_CONTEXT; - eglDestroyContext(p->egl.display, p->egl.context); - close(p->drm_params.render_fd); + if (p->drm_params.render_fd != -1) + close(p->drm_params.render_fd); } }