[PATCH 2/4] winex11: move XDestroyWindow() after free_gl_drawable() in set_win_format()

Miklós Máté mtmkls at gmail.com
Mon Apr 3 16:24:21 CDT 2017


XDestroyWindow() must always come after glXDestroyWindow()

Signed-off-by: Miklós Máté <mtmkls at gmail.com>
---
 dlls/winex11.drv/opengl.c | 29 +++++++++++++++++++++++------
 dlls/winex11.drv/window.c |  1 -
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c
index cde7e0b136..3f26a1830b 100644
--- a/dlls/winex11.drv/opengl.c
+++ b/dlls/winex11.drv/opengl.c
@@ -1334,21 +1334,21 @@ static void free_gl_drawable( struct gl_drawable *gl )
 /***********************************************************************
  *              create_gl_drawable
  */
-static BOOL create_gl_drawable( HWND hwnd, struct gl_drawable *gl )
+static BOOL create_gl_drawable( HWND hwnd, struct gl_drawable *gl, struct x11drv_win_data *data )
 {
     gl->drawable = 0;
 
     if (GetAncestor( hwnd, GA_PARENT ) == GetDesktopWindow())  /* top-level window */
     {
-        struct x11drv_win_data *data = get_win_data( hwnd );
-
         if (data)
         {
             gl->type = DC_GL_WINDOW;
             gl->window = create_client_window( data, gl->visual );
             if (gl->window)
+            {
                 gl->drawable = pglXCreateWindow( gdi_display, gl->format->fbconfig, gl->window, NULL );
-            release_win_data( data );
+                XSync( gdi_display, False );
+            }
         }
     }
 #ifdef SONAME_LIBXCOMPOSITE
@@ -1416,6 +1416,8 @@ static BOOL create_gl_drawable( HWND hwnd, struct gl_drawable *gl )
 static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
 {
     struct gl_drawable *gl, *prev;
+    Window old_client_window = None;
+    struct x11drv_win_data *data;
 
     gl = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*gl) );
     /* Default GLX and WGL swap interval is 1, but in case of glXSwapIntervalSGI
@@ -1435,12 +1437,19 @@ static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
     gl->rect.right  = min( max( 1, gl->rect.right ), 65535 );
     gl->rect.bottom = min( max( 1, gl->rect.bottom ), 65535 );
 
-    if (!create_gl_drawable( hwnd, gl ))
+    data = get_win_data( hwnd );
+    if (data) {
+        old_client_window = data->client_window;
+    }
+
+    if (!create_gl_drawable( hwnd, gl, data ))
     {
+        release_win_data( data );
         XFree( gl->visual );
         HeapFree( GetProcessHeap(), 0, gl );
         return FALSE;
     }
+    release_win_data( data );
 
     TRACE( "created GL drawable %lx for win %p %s\n",
            gl->drawable, hwnd, debugstr_fbconfig( format->fbconfig ));
@@ -1452,6 +1461,10 @@ static BOOL set_win_format( HWND hwnd, const struct wgl_pixel_format *format )
     {
         gl->swap_interval = prev->swap_interval;
         free_gl_drawable( prev );
+        XSync( gdi_display, False );
+        if (old_client_window) {
+            XDestroyWindow( data->display, old_client_window );
+        }
     }
     XSaveContext( gdi_display, (XID)hwnd, gl_hwnd_context, (char *)gl );
     LeaveCriticalSection( &context_section );
@@ -1566,6 +1579,7 @@ void set_gl_drawable_parent( HWND hwnd, HWND parent )
 {
     struct gl_drawable *gl;
     GLXDrawable old_drawable;
+    struct x11drv_win_data *data;
 
     if (!(gl = get_gl_drawable( hwnd, 0 ))) return;
 
@@ -1591,15 +1605,18 @@ void set_gl_drawable_parent( HWND hwnd, HWND parent )
         goto done;
     }
 
-    if (!create_gl_drawable( hwnd, gl ))
+    data = get_win_data( hwnd );
+    if (!create_gl_drawable( hwnd, gl, data ))
     {
         XDeleteContext( gdi_display, (XID)hwnd, gl_hwnd_context );
+        release_win_data( data );
         release_gl_drawable( gl );
         XFree( gl->visual );
         HeapFree( GetProcessHeap(), 0, gl );
         __wine_set_pixel_format( hwnd, 0 );
         return;
     }
+    release_win_data( data );
     mark_drawable_dirty( old_drawable, gl->drawable );
 
 done:
diff --git a/dlls/winex11.drv/window.c b/dlls/winex11.drv/window.c
index 7408a0eb48..5faf801d93 100644
--- a/dlls/winex11.drv/window.c
+++ b/dlls/winex11.drv/window.c
@@ -1437,7 +1437,6 @@ Window create_client_window( struct x11drv_win_data *data, const XVisualInfo *vi
     if (data->client_window)
     {
         XDeleteContext( data->display, data->client_window, winContext );
-        XDestroyWindow( data->display, data->client_window );
     }
 
     if (data->colormap) XFreeColormap( data->display, data->colormap );
-- 
2.11.0




More information about the wine-patches mailing list