kmsdrm: properly exit with an error when ATOMIC interface is not yet available, instead of just segfaulting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index b9f7792..7b0fb64 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -1144,6 +1144,8 @@ KMSDRM_VideoInit(_THIS)
char devname[32];
SDL_VideoDisplay display = {0};
+ viddata->video_init = SDL_FALSE;
+
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (!dispdata) {
return SDL_OutOfMemory();
@@ -1328,8 +1330,6 @@ KMSDRM_VideoInit(_THIS)
display.driverdata = dispdata;
SDL_AddVideoDisplay(&display, SDL_FALSE);
-
-
/* Use this if you ever need to see info on all available planes. */
#if 0
get_planes_info(_this);
@@ -1381,7 +1381,7 @@ KMSDRM_VideoInit(_THIS)
create it is not fatal. */
dispdata->dumb_buffer = KMSDRM_CreateBuffer(_this);
if (!dispdata->dumb_buffer) {
- ret = SDL_SetError("can't find suitable display plane.");
+ ret = SDL_SetError("can't create dumb buffer.");
} else {
/* Fill the dumb buffer with black pixels. */
KMSDRM_FillDumbBuffer(dispdata->dumb_buffer);
@@ -1397,6 +1397,8 @@ KMSDRM_VideoInit(_THIS)
KMSDRM_InitMouse(_this);
+ viddata->video_init = SDL_TRUE;
+
cleanup:
if (encoder)
@@ -1433,11 +1435,21 @@ void
KMSDRM_VideoQuit(_THIS)
{
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
- SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
+ SDL_DisplayData *dispdata;
+
KMSDRM_PlaneInfo plane_info = {0};
- drmModeModeInfo mode = dispdata->crtc->crtc->mode;
+ drmModeModeInfo mode;
+
uint32_t blob_id;
+ /* Video was not initialized properly, hence SDL internals
+ called VideoQuit(). We will segault somewhere if we go further. */
+ if (!viddata->video_init) {
+ return;
+ }
+
+ dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
+
/*****************************************************************/
/* */
/* BLOCK to safely destroy the DUMB BUFFER. */
@@ -1468,8 +1480,9 @@ KMSDRM_VideoQuit(_THIS)
/* */
/*****************************************************************/
-#if AMDGPU_COMPAT
+ mode = dispdata->crtc->crtc->mode;
+#if AMDGPU_COMPAT
plane_info.plane = dispdata->display_plane;
plane_info.crtc_id = dispdata->crtc->crtc->crtc_id;
plane_info.fb_id = dispdata->crtc->crtc->buffer_id;
@@ -1575,6 +1588,7 @@ KMSDRM_VideoQuit(_THIS)
#ifdef SDL_INPUT_LINUXEV
SDL_EVDEV_Quit();
#endif
+ viddata->video_init = SDL_FALSE;
}
#if 0
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index cba9729..6bec4e3 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -90,6 +90,9 @@ typedef struct SDL_VideoData
SDL_Window **windows;
unsigned int max_windows;
unsigned int num_windows;
+
+ SDL_bool video_init; /* Has VideoInit succeeded? */
+
} SDL_VideoData;
typedef struct plane {