OSDN Git Service

Check X11 return status.
authorNicolas Capens <capn@google.com>
Tue, 13 Mar 2018 14:54:18 +0000 (10:54 -0400)
committerNicolas Capens <nicolascapens@google.com>
Tue, 13 Mar 2018 15:28:18 +0000 (15:28 +0000)
We weren't checking the return status of an XGetWindowAttributes() call
while checking for a resized window. It appears that it can start to
fail possibly due to an out-of-memory situation or the window being
destroyed before the EGL surface.

Note that the EGL spec does not have a recommendation on how to handle
this situation. Generating EGL_BAD_ALLOC is intended for eglCreate*
call failures, while EGL_BAD_NATIVE_WINDOW appears to be reserved for
calls that take a native window as a parameter. eglSwapBuffers is
neither.

Bug chromium:819481

Change-Id: I270730567b5179ee43b814e8bd017b601dfbe079
Reviewed-on: https://swiftshader-review.googlesource.com/17708
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
src/OpenGL/libEGL/Display.cpp
src/OpenGL/libEGL/Surface.cpp

index 9e56918..0e58125 100644 (file)
@@ -567,7 +567,7 @@ bool Display::isValidWindow(EGLNativeWindowType window)
                        XWindowAttributes windowAttributes;
                        Status status = libX11->XGetWindowAttributes((::Display*)nativeDisplay, window, &windowAttributes);
 
-                       return status == True;
+                       return status != 0;
                }
                return false;
        #elif defined(__APPLE__)
index 3d17cba..d373990 100644 (file)
@@ -269,7 +269,9 @@ bool WindowSurface::checkForResize()
 {
        #if defined(_WIN32)
                RECT client;
-               if(!GetClientRect(window, &client))
+               BOOL status = GetClientRect(window, &client);
+
+               if(status == 0)
                {
                        return error(EGL_BAD_NATIVE_WINDOW, false);
                }
@@ -281,7 +283,12 @@ bool WindowSurface::checkForResize()
                int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight);
        #elif defined(__linux__)
                XWindowAttributes windowAttributes;
-               libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
+               Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
+
+               if(status == 0)
+               {
+                       return error(EGL_BAD_NATIVE_WINDOW, false);
+               }
 
                int windowWidth = windowAttributes.width;
                int windowHeight = windowAttributes.height;