Skip to content

Commit ca988db

Browse files
Everett Aftonicculus
Everett Afton
authored andcommitted
Bail out if Xrandr returns zero CRTCs in the X11 messagebox implementation
1 parent c147ddf commit ca988db

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/video/x11/SDL_x11messagebox.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,25 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
524524
#ifdef SDL_VIDEO_DRIVER_X11_XRANDR
525525
else if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, use_xrandr_by_default) && data->xrandr) {
526526
XRRScreenResources *screen = X11_XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
527+
if (!screen) {
528+
goto XRANDRBAIL;
529+
}
530+
if (!screen->ncrtc) {
531+
goto XRANDRBAIL;
532+
}
533+
527534
XRRCrtcInfo *crtc_info = X11_XRRGetCrtcInfo(display, screen, screen->crtcs[0]);
528-
x = (crtc_info->width - data->dialog_width) / 2;
529-
y = (crtc_info->height - data->dialog_height) / 3;
535+
if (crtc_info) {
536+
x = (crtc_info->width - data->dialog_width) / 2;
537+
y = (crtc_info->height - data->dialog_height) / 3;
538+
} else {
539+
goto XRANDRBAIL;
540+
}
530541
}
531542
#endif
532543
else {
533544
// oh well. This will misposition on a multi-head setup. Init first next time.
545+
XRANDRBAIL:
534546
x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
535547
y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;
536548
}

0 commit comments

Comments
 (0)