kmsdrm: fix errors when trying to free up videomode driverdata pointers on quit.
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
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index e845f03..49b577f 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -1338,12 +1338,13 @@ KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
}
#endif
+#if 1
/* We are NOT really changing the physical display mode, but using
the PRIMARY PLANE and CRTC to scale as we please. But we need that SDL
has knowledge of the video modes we are going to use for fullscreen
window sizes, even if we are faking their use. If not, SDL only considers
the in-use video mode as available, and sets every window to that size
-before we get to CreateWindow or ReconfigureWindow. */
+before we get to CreateWindow or ReconfigureWindow. */
void
KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
{
@@ -1352,14 +1353,24 @@ KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
SDL_DisplayMode mode;
for (int i = 0; i < conn->count_modes; i++) {
+ SDL_DisplayModeData *modedata = SDL_calloc(1, sizeof(SDL_DisplayModeData));
+
+ if (modedata) {
+ modedata->mode_index = i;
+ }
+
mode.w = conn->modes[i].hdisplay;
mode.h = conn->modes[i].vdisplay;
mode.refresh_rate = conn->modes[i].vrefresh;
mode.format = SDL_PIXELFORMAT_ARGB8888;
+ mode.driverdata = modedata;
- SDL_AddDisplayMode(display, &mode);
- }
+ if (!SDL_AddDisplayMode(display, &mode)) {
+ SDL_free(modedata);
+ }
+ }
}
+#endif
int
KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 16bee13..ab4ea1e 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -132,6 +132,11 @@ typedef struct SDL_WindowData
} SDL_WindowData;
+typedef struct SDL_DisplayModeData
+{
+ int mode_index;
+} SDL_DisplayModeData;
+
typedef struct KMSDRM_FBInfo
{
int drm_fd; /* DRM file desc */