Commit 0d2c75f4 by Corentin Wallez Committed by Commit Bot

DisplayGLX::isValidNativeWindow, avoid X11 exiting the program

The previous implementation of the function had an incorrect comment that implied XQueryTree was a great way to check if a Window is valid. Any X11 function taking a Window is a good candidate, what we need to be careful about is X11 exiting the program on any error. Replace it with a call to XGetWindowAttributes while ignoring X11 errors. This fix was found while implementing similar functionality in Dawn. Bug: dawn:269 Change-Id: I777e59cddbe94baf63286d11887b58c63ac2b66c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2001301Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 0c6c9a0d
......@@ -708,23 +708,16 @@ egl::Error DisplayGLX::restoreLostDevice(const egl::Display *display)
bool DisplayGLX::isValidNativeWindow(EGLNativeWindowType window) const
{
// There is no function in Xlib to check the validity of a Window directly.
// However a small number of functions used to obtain window information
// return a status code (0 meaning failure) and guarantee that they will
// fail if the window doesn't exist (the rational is that these function
// are used by window managers). Out of these function we use XQueryTree
// as it seems to be the simplest; a drawback is that it will allocate
// memory for the list of children, because we use a child window for
// WindowSurface.
Window root;
Window parent;
Window *children = nullptr;
unsigned nChildren;
int status = XQueryTree(mGLX.getDisplay(), window, &root, &parent, &children, &nChildren);
if (children)
{
XFree(children);
}
// Check the validity of the window by calling a getter function on the window that
// returns a status code. If the window is bad the call return a status of zero. We
// need to set a temporary X11 error handler while doing this because the default
// X11 error handler exits the program on any error.
auto oldErrorHandler = XSetErrorHandler(IgnoreX11Errors);
XWindowAttributes attributes;
int status = XGetWindowAttributes(mXDisplay, window, &attributes);
XSetErrorHandler(oldErrorHandler);
return status != 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment