From 87f9a0e106f1a9a2644158fcb738c8572eeb67d1 Mon Sep 17 00:00:00 2001
From: eafton <[EMAIL REDACTED]>
Date: Sun, 5 Oct 2025 01:10:12 +0300
Subject: [PATCH] X11TK: Add more checks to the Xrandr code path to avoid
errors
---
src/video/x11/SDL_x11toolkit.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/video/x11/SDL_x11toolkit.c b/src/video/x11/SDL_x11toolkit.c
index 7c536775abaaf..14aba12a3afe5 100644
--- a/src/video/x11/SDL_x11toolkit.c
+++ b/src/video/x11/SDL_x11toolkit.c
@@ -999,7 +999,14 @@ bool X11Toolkit_CreateWindowRes(SDL_ToolkitWindowX11 *data, int w, int h, int cx
goto FIRSTOUTPUTXRANDR;
}
- crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtc);
+ if (out_info->crtc != None) {
+ crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtc);
+ } else if (out_info->ncrtc > 0) {
+ crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtcs[0]);
+ } else {
+ crtc_info = NULL;
+ }
+
if (crtc_info) {
x = (crtc_info->width - data->window_width) / 2;
y = (crtc_info->height - data->window_height) / 3;
@@ -1020,7 +1027,14 @@ bool X11Toolkit_CreateWindowRes(SDL_ToolkitWindowX11 *data, int w, int h, int cx
goto FIRSTCRTCXRANDR;
}
- crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtc);
+ if (out_info->crtc != None) {
+ crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtc);
+ } else if (out_info->ncrtc > 0) {
+ crtc_info = X11_XRRGetCrtcInfo(display, screen_res, out_info->crtcs[0]);
+ } else {
+ crtc_info = NULL;
+ }
+
if (!crtc_info) {
X11_XRRFreeOutputInfo(out_info);
goto FIRSTCRTCXRANDR;