From a6d022c257a3f2e0b626fd2d0fd3fca71ba84e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 19 Mar 2020 23:28:21 +0100 Subject: [PATCH] X11: Improve window handle race condition The non-root parent window owned by the WM could be destroyed before we process the ConfigureNotify event using the cached parent handle. Bug was found by unmapping a decorated window. This like all uses of the Xlib error handler is not thread safe and there is nothing we can do about that short of moving to XCB. Fixes #1633. (cherry picked from commit e65de2941c056ee5833b4dab3db36b297b53aa14) --- README.md | 1 + src/x11_window.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index e08d56c9..b4d4163c 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ information on what to include when reporting a bug. - [X11] Bugfix: IME input of CJK was broken for "C" locale (#1587,#1636) - [X11] Bugfix: Xlib errors caused by other parts of the application could be reported as GLFW errors + - [X11] Bugfix: A handle race condition could cause a `BadWindow` error (#1633) ## Contact diff --git a/src/x11_window.c b/src/x11_window.c index 3c03ccda..df622147 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1557,6 +1557,8 @@ static void processEvent(XEvent *event) // the position into root (screen) coordinates if (!event->xany.send_event && window->x11.parent != _glfw.x11.root) { + _glfwGrabErrorHandlerX11(); + Window dummy; XTranslateCoordinates(_glfw.x11.display, window->x11.parent, @@ -1564,6 +1566,10 @@ static void processEvent(XEvent *event) xpos, ypos, &xpos, &ypos, &dummy); + + _glfwReleaseErrorHandlerX11(); + if (_glfw.x11.errorCode == BadWindow) + return; } if (xpos != window->x11.xpos || ypos != window->x11.ypos)