[PATCH 3/5] wined3d: Validate the D3D context in FindContext().

Henri Verbeet hverbeet at codeweavers.com
Tue Oct 20 04:05:04 CDT 2009


Apparently it's valid to use a D3D device after its window is destroyed.
OpenGL isn't always so forgiving, so this patch is a first step to avoid
making GL calls on a context without window.
---
 dlls/wined3d/context.c         |   17 +++++++++++++++++
 dlls/wined3d/wined3d_private.h |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 701e024..16304ee 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -782,6 +782,18 @@ BOOL context_set_current(struct wined3d_context *ctx)
     return TlsSetValue(wined3d_context_tls_idx, ctx);
 }
 
+static void context_validate(struct wined3d_context *context)
+{
+    HWND wnd = WindowFromDC(context->hdc);
+
+    if (wnd != context->win_handle)
+    {
+        WARN("DC %p belongs to window %p instead of %p.\n",
+                context->hdc, wnd, context->win_handle);
+        context->valid = 0;
+    }
+}
+
 /*****************************************************************************
  * Context_MarkStateDirty
  *
@@ -1247,6 +1259,7 @@ struct wined3d_context *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceI
         }
         goto out;
     }
+    ret->valid = 1;
     ret->gl_info = &This->adapter->gl_info;
     ret->surface = (IWineD3DSurface *) target;
     ret->current_rt = (IWineD3DSurface *)target;
@@ -1771,6 +1784,7 @@ static inline struct wined3d_context *FindContext(IWineD3DDeviceImpl *This, IWin
 
     if (current_context && current_context->current_rt == target)
     {
+        context_validate(current_context);
         return current_context;
     }
 
@@ -1858,6 +1872,8 @@ retry:
         context->render_offscreen = TRUE;
     }
 
+    context_validate(context);
+
     if (context->render_offscreen != old_render_offscreen)
     {
         Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable);
@@ -2007,6 +2023,7 @@ struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurfac
     TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
 
     context = FindContext(This, target, tid);
+    if (!context->valid) return context;
 
     gl_info = context->gl_info;
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 4b6cb4c..9c4bd5e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1055,6 +1055,7 @@ struct wined3d_context
     WORD num_untracked_materials : 2;   /* Max value 2 */
     WORD current : 1;
     WORD destroyed : 1;
+    WORD valid : 1;
     BYTE texShaderBumpMap;              /* MAX_TEXTURES, 8 */
     BYTE lastWasPow2Texture;            /* MAX_TEXTURES, 8 */
     DWORD                   numbered_array_mask;
-- 
1.6.4.4




More information about the wine-patches mailing list