[PATCH v2] d3d9: Don't assert on invalid IDirect3DBaseTexture9 interfaces.

Henri Verbeet hverbeet at codeweavers.com
Tue Aug 4 03:47:57 CDT 2015


---
v2: Fix a minor typo in the WARN message.

This supersedes patch 113400.

 dlls/d3d9/tests/device.c | 22 ++++++++++++++++++++--
 dlls/d3d9/texture.c      | 12 +++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index cb4a6e8..e58d1df 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -6627,8 +6627,9 @@ static void test_filter(void)
     DestroyWindow(window);
 }
 
-static void test_get_texture(void)
+static void test_get_set_texture(void)
 {
+    const IDirect3DBaseTexture9Vtbl *texture_vtbl;
     IDirect3DBaseTexture9 *texture;
     IDirect3DDevice9 *device;
     IDirect3D9 *d3d;
@@ -6655,6 +6656,23 @@ static void test_get_texture(void)
     ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
     ok(!texture, "Got unexpected texture %p.\n", texture);
 
+    hr = IDirect3DDevice9_CreateTexture(device, 16, 16, 1, 0, D3DFMT_A8R8G8B8,
+            D3DPOOL_MANAGED, (IDirect3DTexture9 **)&texture, NULL);
+    ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
+    texture_vtbl = texture->lpVtbl;
+    texture->lpVtbl = (IDirect3DBaseTexture9Vtbl *)0xdeadbeef;
+    hr = IDirect3DDevice9_SetTexture(device, 0, texture);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    texture->lpVtbl = NULL;
+    hr = IDirect3DDevice9_SetTexture(device, 0, texture);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_SetTexture(device, 0, NULL);
+    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
+    texture->lpVtbl = texture_vtbl;
+    IDirect3DBaseTexture9_Release(texture);
+
     refcount = IDirect3DDevice9_Release(device);
     ok(!refcount, "Device has %u references left.\n", refcount);
     IDirect3D9_Release(d3d);
@@ -10231,7 +10249,7 @@ START_TEST(device)
     test_cube_textures();
     test_mipmap_gen();
     test_filter();
-    test_get_texture();
+    test_get_set_texture();
     test_lod();
     test_surface_get_container();
     test_surface_alignment();
diff --git a/dlls/d3d9/texture.c b/dlls/d3d9/texture.c
index c1a0277..1f8f0f2 100644
--- a/dlls/d3d9/texture.c
+++ b/dlls/d3d9/texture.c
@@ -1252,9 +1252,15 @@ struct d3d9_texture *unsafe_impl_from_IDirect3DBaseTexture9(IDirect3DBaseTexture
 {
     if (!iface)
         return NULL;
-    assert(iface->lpVtbl == (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl
-            || iface->lpVtbl == (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl
-            || iface->lpVtbl == (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl);
+
+    if (iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_2d_vtbl
+            && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_cube_vtbl
+            && iface->lpVtbl != (const IDirect3DBaseTexture9Vtbl *)&d3d9_texture_3d_vtbl)
+    {
+        WARN("%p is not a valid IDirect3DBaseTexture9 interface.\n", iface);
+        return NULL;
+    }
+
     return CONTAINING_RECORD(iface, struct d3d9_texture, IDirect3DBaseTexture9_iface);
 }
 
-- 
2.1.4




More information about the wine-patches mailing list