Fixed bug 5007 - Segfault in KMSDRM_VideoQuit() on Raspberry Pi Zero with no display attached
authorSam Lantinga <slouken@libsdl.org>
Mon, 02 Mar 2020 14:55:40 -0800
changeset 13577d28975f16368
parent 13576 dce2898245ef
child 13578 3e9f11265172
Fixed bug 5007 - Segfault in KMSDRM_VideoQuit() on Raspberry Pi Zero with no display attached

Charles Huber

This patch fixes the segfault on my Pi, though the valid display index range reported by the CHECK_DISPLAY_INDEX() macro in src/video/SDL_video.c is a little weird:

$ SDL_VIDEO_EGL_DRIVER=libEGL.so SDL_VIDEO_GL_DRIVER=libGLESv2.so ./a.out
SDL_Init(): displayIndex must be in the range 0 - -1
src/video/kmsdrm/SDL_kmsdrmvideo.c
     1.1 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c	Mon Mar 02 11:39:44 2020 -0800
     1.2 +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c	Mon Mar 02 14:55:40 2020 -0800
     1.3 @@ -650,7 +650,7 @@
     1.4      viddata->num_windows = 0;
     1.5  
     1.6      /* Restore saved CRTC settings */
     1.7 -    if (viddata->drm_fd >= 0 && dispdata->conn && dispdata->saved_crtc) {
     1.8 +    if (viddata->drm_fd >= 0 && dispdata && dispdata->conn && dispdata->saved_crtc) {
     1.9          drmModeConnector *conn = dispdata->conn;
    1.10          drmModeCrtc *crtc = dispdata->saved_crtc;
    1.11  
    1.12 @@ -661,11 +661,11 @@
    1.13              SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original CRTC mode");
    1.14          }
    1.15      }
    1.16 -    if (dispdata->conn) {
    1.17 +    if (dispdata && dispdata->conn) {
    1.18          KMSDRM_drmModeFreeConnector(dispdata->conn);
    1.19          dispdata->conn = NULL;
    1.20      }
    1.21 -    if (dispdata->saved_crtc) {
    1.22 +    if (dispdata && dispdata->saved_crtc) {
    1.23          KMSDRM_drmModeFreeCrtc(dispdata->saved_crtc);
    1.24          dispdata->saved_crtc = NULL;
    1.25      }