From aa9bc4c509e5956ea276020da733c2f6345aa140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Mon, 1 Dec 2014 22:46:46 +0100 Subject: [PATCH] d3d9: Refuse to reset a lost device. --- dlls/d3d9/device.c | 6 ++++++ dlls/d3d9/tests/d3d9ex.c | 17 +++++++++++++++++ dlls/d3d9/tests/device.c | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 67a56299086..e2e3504848b 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -635,6 +635,12 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Reset(IDirect3DDevice9Ex *if TRACE("iface %p, present_parameters %p.\n", iface, present_parameters); + if (!device->d3d_parent->extended && device->device_state == D3D9_DEVICE_STATE_LOST) + { + WARN("App not active, returning D3DERR_DEVICELOST.\n"); + return D3DERR_DEVICELOST; + } + wined3d_mutex_lock(); if (device->vertex_buffer) diff --git a/dlls/d3d9/tests/d3d9ex.c b/dlls/d3d9/tests/d3d9ex.c index 226e3382957..0ac9db712a9 100644 --- a/dlls/d3d9/tests/d3d9ex.c +++ b/dlls/d3d9/tests/d3d9ex.c @@ -1374,6 +1374,23 @@ static void test_lost_device(void) hr = IDirect3DDevice9Ex_CheckDeviceState(device, NULL); ok(hr == S_PRESENT_OCCLUDED, "Got unexpected hr %#x.\n", hr); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + hr = IDirect3DDevice9Ex_Present(device, NULL, NULL, NULL, NULL); + ok(hr == S_PRESENT_OCCLUDED, "Got unexpected hr %#x.\n", hr); + hr = reset_device(device, &desc); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9Ex_TestCooperativeLevel(device); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9Ex_Present(device, NULL, NULL, NULL, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9Ex_PresentEx(device, NULL, NULL, NULL, NULL, 0); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9Ex_CheckDeviceState(device, window); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = IDirect3DDevice9Ex_CheckDeviceState(device, NULL); + ok(hr == S_PRESENT_OCCLUDED, "Got unexpected hr %#x.\n", hr); + refcount = IDirect3DDevice9Ex_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); done: diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index cd6a9bd4ad7..a5cab968813 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -9751,6 +9751,17 @@ static void test_lost_device(void) hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ret = SetForegroundWindow(GetDesktopWindow()); + ok(ret, "Failed to set foreground window.\n"); + hr = reset_device(device, &device_desc); + ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr); + ret = ShowWindow(window, SW_RESTORE); + ok(ret, "Failed to restore window.\n"); + ret = SetForegroundWindow(window); + ok(ret, "Failed to set foreground window.\n"); + hr = reset_device(device, &device_desc); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + refcount = IDirect3DDevice9_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); done: