d3d9: Don't assert on invalid IDirect3DBaseTexture9 interfaces.

oldstable
Henri Verbeet 2015-08-04 10:47:57 +02:00 committed by Alexandre Julliard
parent cd59e3db6c
commit 0c8e78f80d
2 changed files with 29 additions and 5 deletions

View File

@ -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();

View File

@ -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);
}