From d0eb7d1d4ada1c87d4aa3433933f1520798a66b6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 23 Apr 2025 09:28:43 +0530 Subject: [PATCH] Nicer error message --- kitty/glfw.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index eb05b5847..3fd03b430 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1330,8 +1330,12 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { } } } else { +#define glfw_failure { \ + PyErr_Format(PyExc_OSError, "Failed to create GLFWwindow. This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL %d.%d drivers.", OPENGL_REQUIRED_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MINOR); \ + return NULL; } + temp_window = glfwCreateWindow(640, 480, "temp", NULL, common_context, NULL); - if (temp_window == NULL) { fatal("Failed to create GLFW temp window! This usually happens because of old/broken OpenGL drivers. kitty requires working OpenGL %d.%d drivers.", OPENGL_REQUIRED_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MINOR); } + if (temp_window == NULL) glfw_failure; get_window_content_scale(temp_window, &xscale, &yscale, &xdpi, &ydpi); } FONTS_DATA_HANDLE fonts_data = load_fonts_data(OPT(font_size), xdpi, ydpi); @@ -1345,7 +1349,8 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { } GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, temp_window ? temp_window : common_context, lsc); if (temp_window) { glfwDestroyWindow(temp_window); temp_window = NULL; } - if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; } + if (glfw_window == NULL) glfw_failure; +#undef glfw_failure glfwMakeContextCurrent(glfw_window); if (is_first_window) gl_init(); // Will make the GPU automatically apply SRGB gamma curve on the resulting framebuffer