diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index 2f281d2..1c8992d 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -4768,6 +4768,105 @@ static void test_rtpatch(void) DestroyWindow(window); } +static void test_InvalidTexture(void) +{ + IDirect3DDevice8 *device; + IDirect3D8 *d3d8; + UINT refcount = 0; + HWND window; + HRESULT hr; + IDirect3DTexture8 *texture = NULL; + IDirect3DTexture8 *texture2 = NULL; + DWORD *d; + + const struct { + float x, y, z; + } quad[] = + { + {-1.0f, -1.0f, -0.5f}, + {-1.0f, 1.0f, -0.5f}, + { 1.0f, -1.0f, 1.5f}, + { 1.0f, 1.0f, 1.5f}, + }; + + if (!(d3d8 = pDirect3DCreate8(D3D_SDK_VERSION))) + { + skip("Failed to create d3d8 object, skipping tests.\n"); + return; + } + + window = CreateWindowA("d3d8_test_wc", "d3d8_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, 0, 0, 0, 0); + if (!(device = create_device(d3d8, window, window, TRUE))) + { + skip("Failed to create a D3D device, skipping tests.\n"); + IDirect3D8_Release(d3d8); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice8_SetVertexShader(device, D3DFVF_XYZ); + + hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture2); + hr = IDirect3DDevice8_CreateTexture(device, 32, 32, 3, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture); + if (texture && texture2) + { + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + + /* HeapFree all memory */ + hr = IDirect3DDevice8_SetTexture(device, 0, NULL); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + IDirect3DTexture8_Release(texture); + + /* Test some values - write to released memory / simulate new heapalloc, + * but due to lack of getting the the same address, just write there. + * By accident dsound seems do overwrite some values in my system, ... it may + * be also overwritten by something else, that's why the old behaviour won't + * work any more. + * Details see bug 33055 */ + d = texture; + d[0] = 0; + + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + +/* + { + IDirect3DTexture8 *texture3 = NULL; + hr = IDirect3DDevice8_GetTexture(device, 0, (IDirect3DBaseTexture8 **) &texture3); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + }*/ + + /* depending on the value in d[] the crash happens at differen positions below here */ + hr = IDirect3DDevice8_SetTexture(device, 0, (IDirect3DBaseTexture8 *) texture2); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + + /* draw */ + hr = IDirect3DDevice8_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice8_DrawPrimitiveUP(device, D3DPT_TRIANGLELIST, 0, quad, sizeof(quad)); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice8_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + + hr = IDirect3DDevice8_SetTexture(device, 0, NULL); + ok(hr == D3D_OK, "SetTexture returned hr %#x.\n", hr); + +#if 0 + /* may crash on win */ + IDirect3DTexture8_Release(texture2); +#endif + } +#if 0 + /* may crash on wine */ + refcount = IDirect3DDevice8_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D8_Release(d3d8); + DestroyWindow(window); +#endif +} + START_TEST(device) { HMODULE d3d8_handle = LoadLibraryA( "d3d8.dll" ); @@ -4799,7 +4898,7 @@ START_TEST(device) screen_width = GetSystemMetrics(SM_CXSCREEN); screen_height = GetSystemMetrics(SM_CYSCREEN); - +/* test_fpu_setup(); test_display_modes(); test_shader_versions(); @@ -4843,7 +4942,8 @@ START_TEST(device) test_surface_lockrect_blocks(); test_set_palette(); test_swvp_buffer(); - test_rtpatch(); + test_rtpatch();*/ + test_InvalidTexture(); } UnregisterClassA("d3d8_test_wc", GetModuleHandleA(NULL)); }