Skip to content

Commit

Permalink
X11: Fix queries crashing if monitor disconnected
Browse files Browse the repository at this point in the history
Merged from downstream kovidgoyal/glfw.  First of many.

Related to glfw#1602.
  • Loading branch information
kovidgoyal authored and elmindreda committed Jan 16, 2020
1 parent 65cfe74 commit a5e5b78
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/x11_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,16 @@ 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);
}
}
Expand Down Expand Up @@ -493,9 +497,15 @@ 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);
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
Expand Down

0 comments on commit a5e5b78

Please sign in to comment.