From d283c5b68e078233cd1e69c1b16d3577af2cc448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 19 May 2016 11:11:45 +0200 Subject: [PATCH] d3d9: Allow to pass NULL pointers to IDirect3DDevice9_GetRenderTargetData(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d9/device.c | 3 +++ dlls/d3d9/tests/device.c | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index dd7f46ada2b..4bbdd42af01 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1279,6 +1279,9 @@ static HRESULT WINAPI d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex *iface, TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, render_target, dst_surface); + if (!render_target || !dst_surface) + return D3DERR_INVALIDCALL; + wined3d_mutex_lock(); wined3d_texture_get_sub_resource_desc(dst_impl->wined3d_texture, dst_impl->sub_resource_idx, &wined3d_desc); dst_rect.left = 0; diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 8860bce3928..4302f76518c 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -11122,6 +11122,55 @@ done: DestroyWindow(window); } +static void test_get_render_target_data(void) +{ + IDirect3DSurface9 *offscreen_surface, *render_target; + IDirect3DDevice9 *device; + IDirect3D9 *d3d; + UINT refcount; + HWND window; + HRESULT hr; + + window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + d3d = Direct3DCreate9(D3D_SDK_VERSION); + ok(!!d3d, "Failed to create a D3D object.\n"); + if (!(device = create_device(d3d, window, NULL))) + { + skip("Failed to create a D3D device.\n"); + IDirect3D9_Release(d3d); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 32, 32, + D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &offscreen_surface, NULL); + ok(SUCCEEDED(hr), "Failed to create offscreen surface, hr %#x.\n", hr); + + hr = IDirect3DDevice9_CreateRenderTarget(device, 32, 32, + D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0, TRUE, &render_target, NULL); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + + hr = IDirect3DDevice9_GetRenderTargetData(device, NULL, NULL); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice9_GetRenderTargetData(device, render_target, NULL); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice9_GetRenderTargetData(device, NULL, offscreen_surface); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + + hr = IDirect3DDevice9_GetRenderTargetData(device, render_target, offscreen_surface); + ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr); + + IDirect3DSurface9_Release(render_target); + IDirect3DSurface9_Release(offscreen_surface); + refcount = IDirect3DDevice9_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + IDirect3D9_Release(d3d); + DestroyWindow(window); +} + START_TEST(device) { WNDCLASSA wc = {0}; @@ -11237,6 +11286,7 @@ START_TEST(device) test_swapchain_parameters(); test_check_device_format(); test_miptree_layout(); + test_get_render_target_data(); UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL)); }