[PATCH 5/6] d3d9: Reject render target surfaces created for other devices.

Józef Kucia jkucia at codeweavers.com
Tue Jan 3 06:46:32 CST 2017


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---

For bug 36959: https://bugs.winehq.org/show_bug.cgi?id=36959

---
 dlls/d3d9/d3d9_private.h |  1 +
 dlls/d3d9/device.c       | 10 ++++++++--
 dlls/d3d9/surface.c      |  7 +++++++
 dlls/d3d9/tests/device.c |  6 +++---
 4 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 3317e9c..20c4c5c 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -230,6 +230,7 @@ struct d3d9_surface
     struct d3d9_texture *texture;
 };
 
+struct d3d9_device *d3d9_surface_get_device(const struct d3d9_surface *surface) DECLSPEC_HIDDEN;
 struct wined3d_rendertarget_view *d3d9_surface_get_rendertarget_view(struct d3d9_surface *surface) DECLSPEC_HIDDEN;
 void surface_init(struct d3d9_surface *surface, struct wined3d_texture *wined3d_texture,
         unsigned int sub_resource_idx, const struct wined3d_parent_ops **parent_ops) DECLSPEC_HIDDEN;
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index dab19ab..d47c705 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -1523,8 +1523,14 @@ static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWO
 
     if (!idx && !surface_impl)
     {
-         WARN("Trying to set render target 0 to NULL.\n");
-         return D3DERR_INVALIDCALL;
+        WARN("Trying to set render target 0 to NULL.\n");
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (surface_impl && d3d9_surface_get_device(surface_impl) != device)
+    {
+        WARN("Render target surface does not match device.\n");
+        return D3DERR_INVALIDCALL;
     }
 
     wined3d_mutex_lock();
diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c
index be68682..12e0f39 100644
--- a/dlls/d3d9/surface.c
+++ b/dlls/d3d9/surface.c
@@ -389,6 +389,13 @@ static const struct wined3d_parent_ops d3d9_view_wined3d_parent_ops =
     view_wined3d_object_destroyed,
 };
 
+struct d3d9_device *d3d9_surface_get_device(const struct d3d9_surface *surface)
+{
+    IDirect3DDevice9Ex *device;
+    device = surface->texture ? surface->texture->parent_device : surface->parent_device;
+    return impl_from_IDirect3DDevice9Ex(device);
+}
+
 struct wined3d_rendertarget_view *d3d9_surface_get_rendertarget_view(struct d3d9_surface *surface)
 {
     HRESULT hr;
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index fbae9d6..aa266a5 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -11375,7 +11375,7 @@ static void test_render_target_device_mismatch(void)
     ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
 
     hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
-    todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
+    ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
 
     IDirect3DSurface9_Release(surface);
 
@@ -11383,13 +11383,13 @@ static void test_render_target_device_mismatch(void)
     ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
 
     hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface);
-    todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
+    ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
 
     IDirect3DSurface9_Release(surface);
 
     hr = IDirect3DDevice9_GetRenderTarget(device, 0, &surface);
     ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
-    todo_wine ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt);
+    ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt);
     IDirect3DSurface9_Release(surface);
     IDirect3DSurface9_Release(rt);
 
-- 
2.7.3




More information about the wine-patches mailing list