Browse Source

Bail out if Xrandr returns zero CRTCs in the X11 messagebox implementation

Everett Afton 4 months ago
parent
commit
ca988dbc2c
1 changed files with 14 additions and 2 deletions
  1. 14 2
      src/video/x11/SDL_x11messagebox.c

+ 14 - 2
src/video/x11/SDL_x11messagebox.c

@@ -524,13 +524,25 @@ static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data)
 #ifdef SDL_VIDEO_DRIVER_X11_XRANDR
 #ifdef SDL_VIDEO_DRIVER_X11_XRANDR
         else if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, use_xrandr_by_default) && data->xrandr) {
         else if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_XRANDR, use_xrandr_by_default) && data->xrandr) {
             XRRScreenResources *screen = X11_XRRGetScreenResourcesCurrent(display, DefaultRootWindow(display));
             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]);
             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
 #endif
         else {
         else {
             // oh well. This will misposition on a multi-head setup. Init first next time.
             // oh well. This will misposition on a multi-head setup. Init first next time.
+			XRANDRBAIL:
             x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
             x = (DisplayWidth(display, data->screen) - data->dialog_width) / 2;
             y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;
             y = (DisplayHeight(display, data->screen) - data->dialog_height) / 3;
         }
         }