RFC - d3d9: Return success for UnlockRect attempts on already unlocked surfaces

Bruno Jesus 00cpxxx at gmail.com
Sun Oct 11 11:36:50 CDT 2015


Hi all, this is an attempt to fix bug 28874 [1]. The tests [2] run
fine up to Windows 8, which unfortunately introduced a change in the
behavior so I'm not sure how to handle this (broken?).

Maybe a similar test is required in other d3d versions and a deeper
change (wined3d_surface_unmap?) required to proper fix this.

[1] - https://bugs.winehq.org/show_bug.cgi?id=28874
[2] - https://testbot.winehq.org/JobDetails.pl?Key=17252

Best wishes,
Bruno
-------------- next part --------------
diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c
index 7dc6e70..00e4b97 100644
--- a/dlls/d3d9/surface.c
+++ b/dlls/d3d9/surface.c
@@ -274,11 +274,12 @@ static HRESULT WINAPI d3d9_surface_UnlockRect(IDirect3DSurface9 *iface)
     hr = wined3d_surface_unmap(surface->wined3d_surface);
     wined3d_mutex_unlock();
 
-    switch(hr)
+    if (hr == WINEDDERR_NOTLOCKED)
     {
-        case WINEDDERR_NOTLOCKED:       return D3DERR_INVALIDCALL;
-        default:                        return hr;
+        TRACE("surface was not locked!\n");
+        hr = S_OK;
     }
+    return hr;
 }
 
 static HRESULT WINAPI d3d9_surface_GetDC(IDirect3DSurface9 *iface, HDC *dc)
diff --git a/dlls/d3d9/tests/d3d9ex.c b/dlls/d3d9/tests/d3d9ex.c
index 151db41..c5e9b11 100644
--- a/dlls/d3d9/tests/d3d9ex.c
+++ b/dlls/d3d9/tests/d3d9ex.c
@@ -708,6 +708,8 @@ static void test_user_memory(void)
     ok(locked_rect.pBits == mem, "Got unexpected pBits %p, expected %p.\n", locked_rect.pBits, mem);
     hr = IDirect3DTexture9_UnlockRect(texture, 0);
     ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
+    hr = IDirect3DTexture9_UnlockRect(texture, 0);
+    ok(SUCCEEDED(hr), "Failed to double unlock texture, hr %#x.\n", hr);
     IDirect3DTexture9_Release(texture);
 
     if (caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP)
@@ -739,6 +741,8 @@ static void test_user_memory(void)
     ok(locked_rect.pBits == mem, "Got unexpected pBits %p, expected %p.\n", locked_rect.pBits, mem);
     hr = IDirect3DSurface9_UnlockRect(surface);
     ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
+    hr = IDirect3DSurface9_UnlockRect(surface);
+    ok(SUCCEEDED(hr), "Failed to double unlock surface, hr %#x.\n", hr);
     IDirect3DSurface9_Release(surface);
 
     hr = IDirect3DDevice9Ex_CreateOffscreenPlainSurfaceEx(device, 128, 128, D3DFMT_A8R8G8B8,
@@ -752,6 +756,8 @@ static void test_user_memory(void)
         ok(locked_rect.pBits == mem, "Got unexpected pBits %p, expected %p.\n", locked_rect.pBits, mem);
         hr = IDirect3DSurface9_UnlockRect(surface);
         ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
+        hr = IDirect3DSurface9_UnlockRect(surface);
+        ok(SUCCEEDED(hr), "Failed to double unlock surface, hr %#x.\n", hr);
         IDirect3DSurface9_Release(surface);
     }
 
@@ -776,6 +782,8 @@ static void test_user_memory(void)
     ok(locked_rect.pBits == mem, "Got unexpected pBits %p, expected %p.\n", locked_rect.pBits, mem);
     hr = IDirect3DTexture9_UnlockRect(texture, 0);
     ok(SUCCEEDED(hr), "Failed to unlock texture, hr %#x.\n", hr);
+    hr = IDirect3DTexture9_UnlockRect(texture, 0);
+    ok(SUCCEEDED(hr), "Failed to double unlock texture, hr %#x.\n", hr);
 
     hr = IDirect3DDevice9Ex_CreateTexture(device, 33, 33, 1, 0, D3DFMT_L8,
             D3DPOOL_DEFAULT, &texture2, NULL);


More information about the wine-devel mailing list