From ca988dbc2c0f1401d3bd36f3a0041f511da3f4e1 Mon Sep 17 00:00:00 2001
From: Everett Afton <[EMAIL REDACTED]>
Date: Wed, 14 May 2025 22:10:51 +0300
Subject: [PATCH] Bail out if Xrandr returns zero CRTCs in the X11 messagebox
implementation
---
src/video/x11/SDL_x11messagebox.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c
index 11a81b22a6a5a..7c94a05b0c9ee 100644
--- a/src/video/x11/SDL_x11messagebox.c
+++ b/src/video/x11/SDL_x11messagebox.c
@@ -524,13 +524,25 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
#ifdef SDL_VIDEO_DRIVER_X11_XRANDR
else if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, use_xrandr_by_default) && data->xrandr) {
XRRScreenResources *screen = X11_XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
+ if (!screen) {
+ goto XRANDRBAIL;
+ }
+ if (!screen->ncrtc) {
+ goto XRANDRBAIL;
+ }
+
XRRCrtcInfo *crtc_info = X11_XRRGetCrtcInfo(display, screen, screen->crtcs[0]);
- x = (crtc_info->width - data->dialog_width) / 2;
- y = (crtc_info->height - data->dialog_height) / 3;
+ if (crtc_info) {
+ x = (crtc_info->width - data->dialog_width) / 2;
+ y = (crtc_info->height - data->dialog_height) / 3;
+ } else {
+ goto XRANDRBAIL;
+ }
}
#endif
else {
// oh well. This will misposition on a multi-head setup. Init first next time.
+ XRANDRBAIL:
x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;
}