From 0d16761cbe39f51bf761db7b989610f58f8649bf Mon Sep 17 00:00:00 2001 From: Manuel Alfayate Corchete Date: Tue, 25 Aug 2020 05:53:13 +0200 Subject: [PATCH] kmsdrm: fix segfault on quit beacuse of freed _this->egl_data. --- src/video/kmsdrm/SDL_kmsdrmopengles.h | 2 +- src/video/kmsdrm/SDL_kmsdrmvideo.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.h b/src/video/kmsdrm/SDL_kmsdrmopengles.h index cd8ec4921..b92b24cf4 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.h +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.h @@ -31,7 +31,7 @@ /* OpenGLES functions */ #define KMSDRM_GLES_GetAttribute SDL_EGL_GetAttribute #define KMSDRM_GLES_GetProcAddress SDL_EGL_GetProcAddress -#define KMSDRM_GLES_UnloadLibrary SDL_EGL_UnloadLibrary +//#define KMSDRM_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define KMSDRM_GLES_DeleteContext SDL_EGL_DeleteContext #define KMSDRM_GLES_GetSwapInterval SDL_EGL_GetSwapInterval diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 00b954ae3..9bfa6dc8a 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -652,7 +652,7 @@ KMSDRM_CreateDevice(int devindex) #if SDL_VIDEO_OPENGL_EGL device->GL_LoadLibrary = KMSDRM_GLES_LoadLibrary; device->GL_GetProcAddress = KMSDRM_GLES_GetProcAddress; - device->GL_UnloadLibrary = KMSDRM_GLES_UnloadLibrary; + //device->GL_UnloadLibrary = KMSDRM_GLES_UnloadLibrary; device->GL_CreateContext = KMSDRM_GLES_CreateContext; device->GL_MakeCurrent = KMSDRM_GLES_MakeCurrent; device->GL_SetSwapInterval = KMSDRM_GLES_SetSwapInterval; @@ -1211,6 +1211,18 @@ KMSDRM_VideoQuit(_THIS) SDL_GL_UnloadLibrary(); } + /* Since drm_atomic_commit() uses EGL functions internally, we need "_this->egl_data" + NOT to be freed by SDL internals before. + SDL internals call device->GL_UnloadLibrary automatically earlier, so we DON'T assign + device->GL_UnloadLibrary to SDL_EGL_UnloadLibrary(), and that way WE DECIDE WHERE + we want to free "_this->egl_data" by manually calling SDL_EGL_UnloadLibrary(), + which happens to be here. + */ + +#if SDL_VIDEO_OPENGL_EGL + SDL_EGL_UnloadLibrary(_this); +#endif + /* Free connector */ if (dispdata && dispdata->connector) { if (dispdata->connector->connector) {