From a19757ac8defbd380715e958bac8e25ea6edb3d2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Mar 2020 14:55:40 -0800 Subject: [PATCH] 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index cbc1704a6..9fb42e94c 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -650,7 +650,7 @@ KMSDRM_VideoQuit(_THIS) viddata->num_windows = 0; /* Restore saved CRTC settings */ - if (viddata->drm_fd >= 0 && dispdata->conn && dispdata->saved_crtc) { + if (viddata->drm_fd >= 0 && dispdata && dispdata->conn && dispdata->saved_crtc) { drmModeConnector *conn = dispdata->conn; drmModeCrtc *crtc = dispdata->saved_crtc; @@ -661,11 +661,11 @@ KMSDRM_VideoQuit(_THIS) SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original CRTC mode"); } } - if (dispdata->conn) { + if (dispdata && dispdata->conn) { KMSDRM_drmModeFreeConnector(dispdata->conn); dispdata->conn = NULL; } - if (dispdata->saved_crtc) { + if (dispdata && dispdata->saved_crtc) { KMSDRM_drmModeFreeCrtc(dispdata->saved_crtc); dispdata->saved_crtc = NULL; }