Skip to content

Commit

Permalink
kmsdrm: fix errors when trying to free up videomode driverdata pointe…
Browse files Browse the repository at this point in the history
…rs on quit.
  • Loading branch information
vanfanel committed Sep 6, 2020
1 parent 9501b1c commit cce6c60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/video/kmsdrm/SDL_kmsdrmvideo.c
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/video/kmsdrm/SDL_kmsdrmvideo.h
Expand Up @@ -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 */
Expand Down

0 comments on commit cce6c60

Please sign in to comment.