From 96c444d041d4a4bd9caaedf47b70044562a8d481 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 21 Aug 2018 12:52:16 +0530 Subject: [PATCH] Workaround for bug in glfw causing crash when hotplugging monitors Fixes #812 --- glfw/x11_monitor.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/glfw/x11_monitor.c b/glfw/x11_monitor.c index 1c115e0ea..ae7075cd2 100644 --- a/glfw/x11_monitor.c +++ b/glfw/x11_monitor.c @@ -326,13 +326,15 @@ void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos) sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); + if (ci) + { + if (xpos) + *xpos = ci->x; + if (ypos) + *ypos = ci->y; - if (xpos) - *xpos = ci->x; - if (ypos) - *ypos = ci->y; - - XRRFreeCrtcInfo(ci); + XRRFreeCrtcInfo(ci); + } XRRFreeScreenResources(sr); } } @@ -411,9 +413,13 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); - *mode = vidmodeFromModeInfo(getModeInfo(sr, ci->mode), 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); + XRRFreeCrtcInfo(ci); + } XRRFreeScreenResources(sr); } else