From 88d4d07745c2867a7c8cdef9ac3cbc80179eb962 Mon Sep 17 00:00:00 2001 From: Francis Lecavalier Date: Wed, 4 Dec 2019 11:03:40 -0500 Subject: [PATCH] X11: Fix crash when querying video mode/position of disconnected monitor --- src/x11_monitor.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 4d3e1a942..3c1bfc404 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -322,12 +322,14 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); - if (xpos) - *xpos = ci->x; - if (ypos) - *ypos = ci->y; + if (ci) { + if (xpos) + *xpos = ci->x; + if (ypos) + *ypos = ci->y; - XRRFreeCrtcInfo(ci); + XRRFreeCrtcInfo(ci); + } XRRFreeScreenResources(sr); } } @@ -493,9 +495,12 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); - *mode = vidmodeFromModeInfo(getModeInfo(sr, ci->mode), ci); - - XRRFreeCrtcInfo(ci); + if (ci) { + const XRRModeInfo* mi = getModeInfo(sr, ci->mode); + if (mi) // mi can be NULL if the monitor has been disconnected + *mode = vidmodeFromModeInfo(mi, ci); + XRRFreeCrtcInfo(ci); + } XRRFreeScreenResources(sr); } else