[PATCH 2/5] wined3d: Allow the first render target to be set to NULL.

Henri Verbeet hverbeet at codeweavers.com
Thu Sep 12 02:20:52 CDT 2013


Note that it still isn't necessarily safe to render in this case, because
there are places where we assume the first render target is always non-NULL in
order to determine e.g. framebuffer dimensions. It's now the responsibility of
the caller to ensure that doesn't happen.
---
 dlls/d3d9/device.c    |    6 ++++++
 dlls/ddraw/device.c   |   11 ++++++++---
 dlls/wined3d/device.c |   10 ++--------
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 17664b1..a70832d 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -1226,6 +1226,12 @@ static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWO
         return D3DERR_INVALIDCALL;
     }
 
+    if (!idx && !surface_impl)
+    {
+         WARN("Trying to set render target 0 to NULL.\n");
+         return D3DERR_INVALIDCALL;
+    }
+
     wined3d_mutex_lock();
     hr = wined3d_device_set_render_target(device->wined3d_device, idx,
             surface_impl ? surface_impl->wined3d_surface : NULL, TRUE);
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 15145c0..2c02d65 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -1827,10 +1827,15 @@ static HRESULT d3d_device_set_render_target(struct d3d_device *device, struct dd
         wined3d_mutex_unlock();
         return D3D_OK;
     }
+    if (!target)
+    {
+        WARN("Trying to set render target to NULL.\n");
+        wined3d_mutex_unlock();
+        return DDERR_INVALIDPARAMS;
+    }
     device->target = target;
-    hr = wined3d_device_set_render_target(device->wined3d_device, 0,
-            target ? target->wined3d_surface : NULL, FALSE);
-    if(hr != D3D_OK)
+    if (FAILED(hr = wined3d_device_set_render_target(device->wined3d_device,
+            0, target->wined3d_surface, FALSE)))
     {
         wined3d_mutex_unlock();
         return hr;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 1b0137f..ef0ba9e 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1350,7 +1350,8 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
     TRACE("Setting rendertarget 0 to NULL\n");
     device->fb.render_targets[0] = NULL;
     TRACE("Releasing the render target at %p\n", surface);
-    wined3d_surface_decref(surface);
+    if (surface)
+        wined3d_surface_decref(surface);
 
     context_release(context);
 
@@ -4482,13 +4483,6 @@ HRESULT CDECL wined3d_device_set_render_target(struct wined3d_device *device,
         return WINED3DERR_INVALIDCALL;
     }
 
-    /* Render target 0 can't be set to NULL. */
-    if (!render_target && !render_target_idx)
-    {
-        WARN("Trying to set render target 0 to NULL.\n");
-        return WINED3DERR_INVALIDCALL;
-    }
-
     if (render_target && !(render_target->resource.usage & WINED3DUSAGE_RENDERTARGET))
     {
         FIXME("Surface %p doesn't have render target usage.\n", render_target);
-- 
1.7.10.4




More information about the wine-patches mailing list