[PATCH 2/2] wined3d: Use backup context if WGL context creation failed in wined3d_context_gl_init().

Paul Gofman gofmanp at gmail.com
Thu Nov 14 14:40:03 CST 2019


Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
    Supersedes 173591.

 dlls/wined3d/context.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 5cb1b927e5..01c1a6376d 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -2022,7 +2022,10 @@ static BOOL wined3d_context_gl_create_wgl_ctx(struct wined3d_context_gl *context
     }
 
     if (!context_gl->pixel_format)
+    {
+        ERR("Failed to choose pixel format.\n");
         return FALSE;
+    }
 
     wined3d_context_gl_enter(context_gl);
 
@@ -2038,6 +2041,7 @@ static BOOL wined3d_context_gl_create_wgl_ctx(struct wined3d_context_gl *context
     {
         if (!(ctx = context_create_wgl_attribs(gl_info, context_gl->dc, share_ctx)))
         {
+            ERR("Failed to create a WGL context.\n");
             context_release(context);
             return FALSE;
         }
@@ -2109,16 +2113,27 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi
     else if (!(context_gl->dc = GetDCEx(context_gl->window, 0, DCX_USESTYLE | DCX_CACHE)))
         WARN("Failed to retrieve device context, trying swapchain backup.\n");
 
-    if (!context_gl->dc)
+    for (i = !context_gl->dc; i < 2; ++i)
     {
-        if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl)))
+        if (i)
         {
-            ERR("Failed to retrieve a device context.\n");
-            return E_FAIL;
+            if (!(context_gl->dc = wined3d_swapchain_gl_get_backup_dc(swapchain_gl)))
+            {
+                ERR("Failed to retrieve a device context.\n");
+                return E_FAIL;
+            }
+            context_gl->dc_is_private = TRUE;
         }
-        context_gl->dc_is_private = TRUE;
+
+        if (wined3d_context_gl_create_wgl_ctx(context_gl, swapchain_gl))
+            break;
+
+        wined3d_release_dc(context_gl->window, context_gl->dc);
     }
 
+    if (i == 2)
+        return E_FAIL;
+
     list_init(&context_gl->fbo_list);
     list_init(&context_gl->fbo_destroy_list);
 
@@ -2166,9 +2181,6 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi
             sizeof(*context_gl->texture_type))))
         goto fail;
 
-    if (!wined3d_context_gl_create_wgl_ctx(context_gl, swapchain_gl))
-        goto fail;
-
     if (context_debug_output_enabled(gl_info))
     {
         GL_EXTCALL(glDebugMessageCallback(wined3d_debug_callback, context));
@@ -2312,6 +2324,7 @@ HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wi
     return WINED3D_OK;
 
 fail:
+    context_release(context);
     heap_free(context_gl->texture_type);
     wined3d_release_dc(context_gl->window, context_gl->dc);
     return E_FAIL;
-- 
2.23.0




More information about the wine-devel mailing list