From fb4123a6f2756fe67ced65cb51afa75a1311c285 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 8 Feb 2019 08:03:16 +0530 Subject: [PATCH] Guard calls to glfwGetMonitorContentScale --- kitty/glfw.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index 1e6159050..de9b2e10a 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -354,7 +354,10 @@ static inline void get_window_dpi(GLFWwindow *w, double *x, double *y) { float xscale = 1, yscale = 1; if (w) glfwGetWindowContentScale(w, &xscale, &yscale); - else glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale); + else { + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + if (monitor) glfwGetMonitorContentScale(monitor, &xscale, &yscale); + } // check for zero or NaN values of xscale/yscale if (!xscale || xscale != xscale) xscale = 1.0; if (!yscale || yscale != yscale) yscale = 1.0; @@ -895,8 +898,8 @@ primary_monitor_size(PYNOARG) { static PyObject* primary_monitor_content_scale(PYNOARG) { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); - float xscale, yscale; - glfwGetMonitorContentScale(monitor, &xscale, &yscale); + float xscale = 1.0, yscale = 1.0; + if (monitor) glfwGetMonitorContentScale(monitor, &xscale, &yscale); return Py_BuildValue("ff", xscale, yscale); }