From 6de70d82522a8b884b1b271686707697ce193238 Mon Sep 17 00:00:00 2001 From: Ivor Wanders Date: Sat, 9 Aug 2025 11:13:20 -0400 Subject: [PATCH 1/2] X11: Prevent BadWindow when creating small windows The glfwCreateWindow function ensures that the width and height are at least greater or equal than zero, but on X11 it is invalid to create a window with dimensions that equal zero, see [1]. This change ensures that the dimensions passed to XCreateWindow are at least 1 by 1. This issue was detected in [2], where a call to glfwCreateWindow was done to request a 1x1 window, with a _glfw.x11.contentScaleX of less than 1.0 (0.958333) this results in a request for a 0x0 window which then causes an BadWindow error from X11. [1]: https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/e003f52661679e95b51ff24e317af6178fe2a73c/specs/libX11/CH03.xml#L1333-1337 [2]: https://github.com/WerWolv/ImHex/pull/2390 --- CONTRIBUTORS.md | 1 + README.md | 2 ++ src/x11_window.c | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index cfb4f42ca..e3956e61d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -282,6 +282,7 @@ video tutorials. - Corentin Wallez - Torsten Walluhn - Patrick Walton + - Ivor Wanders - Jim Wang - Xo Wang - Andre Weissflog diff --git a/README.md b/README.md index 1c7ced36e..5e882e277 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,8 @@ information on what to include when reporting a bug. - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless` - [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to `GLFW_NATIVE_CONTEXT_API` (#2518) + - [X11] Bugfix: Prevent BadWindow when creating small windows with a content scale + less than 1 (#2754) ## Contact diff --git a/src/x11_window.c b/src/x11_window.c index 986bfb93b..65d7eb2cb 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -576,6 +576,10 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, height *= _glfw.x11.contentScaleY; } + // The dimensions must be nonzero, or a BadValue error results. + width = _glfw_max(1, width); + height = _glfw_max(1, height); + int xpos = 0, ypos = 0; if (wndconfig->xpos != GLFW_ANY_POSITION && wndconfig->ypos != GLFW_ANY_POSITION) From 4df5129529b1af57d04a51f09145da5079822c3e Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sat, 6 Sep 2025 07:33:27 -0700 Subject: [PATCH 2/2] X11: check crtcInfo for NULL when polling monitors --- CONTRIBUTORS.md | 1 + README.md | 1 + src/x11_monitor.c | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e3956e61d..0e1d88342 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -287,6 +287,7 @@ video tutorials. - Xo Wang - Andre Weissflog - Jay Weisskopf + - Drew Weymouth - Frank Wille - Andy Williams - Joel Winarske diff --git a/README.md b/README.md index 5e882e277..586d6be25 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ information on what to include when reporting a bug. - [Wayland] Bugfix: The cursor position was not updated when clicking through from a modal to the content area - [X11] Bugfix: Running without a WM could trigger an assert (#2593,#2601,#2631) + - [X11] Bugfix: Occasional crash when an idle display awakes (#2766) - [Null] Added Vulkan 'window' surface creation via `VK_EXT_headless_surface` - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless` - [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 3af827520..74c57ed01 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -151,6 +151,11 @@ void _glfwPollMonitorsX11(void) } XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc); + if (!ci) { + XRRFreeOutputInfo(oi); + continue; + } + if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270) { widthMM = oi->mm_height;