[PATCH 10/10] wined3d: Avoid some common invalid context accesses.

Henri Verbeet hverbeet at codeweavers.com
Wed Mar 17 15:59:54 CDT 2010


Unfortunately there are plenty of other places left. Perhaps we should
consider creating our own window when the context becomes invalid and making
the context current on that instead.
---
 dlls/wined3d/device.c    |   13 +++++++++++++
 dlls/wined3d/drawprim.c  |    6 ++++++
 dlls/wined3d/swapchain.c |    6 ++++++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 2d3ec56..bd13451 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4369,6 +4369,12 @@ HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfac
     }
 
     context = context_acquire(This, (IWineD3DSurface *)target, CTXUSAGE_CLEAR);
+    if (!context->valid)
+    {
+        context_release(context);
+        WARN("Invalid context, skipping clear.\n");
+        return WINED3D_OK;
+    }
 
     target->get_drawable_size(context, &drawable_width, &drawable_height);
 
@@ -5842,6 +5848,13 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
     else if (!surface_is_offscreen(dst_surface)) context = context_acquire(This, dst_surface, CTXUSAGE_RESOURCELOAD);
     else context = context_acquire(This, NULL, CTXUSAGE_RESOURCELOAD);
 
+    if (!context->valid)
+    {
+        context_release(context);
+        WARN("Invalid context, skipping blit.\n");
+        return;
+    }
+
     gl_info = context->gl_info;
 
     if (!surface_is_offscreen(src_surface))
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 0ed0e11..da7aab4 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -596,6 +596,12 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT
     This->isInDraw = TRUE;
 
     context = context_acquire(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
+    if (!context->valid)
+    {
+        context_release(context);
+        WARN("Invalid context, skipping draw.\n");
+        return;
+    }
 
     if (This->stencilBufferTarget) {
         /* Note that this depends on the context_acquire() call above to set
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index dfe194d..776aa68 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -223,6 +223,12 @@ static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CO
     IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);
 
     context = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
+    if (!context->valid)
+    {
+        context_release(context);
+        WARN("Invalid context, skipping present.\n");
+        return WINED3D_OK;
+    }
 
     /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
     if (This->device->bCursorVisible && This->device->cursorTexture)
-- 
1.6.4.4




More information about the wine-patches mailing list