[PATCH 1/5] d3d8: Clear pBits and Pitch when d3d8_surface_LockRect() fails.

Henri Verbeet hverbeet at codeweavers.com
Tue Nov 12 04:00:25 CST 2013


This is a only slightly modified version of a patch by Lasse Rasinen.
---
 dlls/d3d8/surface.c      |   12 ++++++++++--
 dlls/d3d8/tests/device.c |    4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c
index a157c51..0b40c46 100644
--- a/dlls/d3d8/surface.c
+++ b/dlls/d3d8/surface.c
@@ -273,8 +273,16 @@ static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface,
     hr = wined3d_surface_map(surface->wined3d_surface, &map_desc, rect, flags);
     wined3d_mutex_unlock();
 
-    locked_rect->Pitch = map_desc.row_pitch;
-    locked_rect->pBits = map_desc.data;
+    if (SUCCEEDED(hr))
+    {
+        locked_rect->Pitch = map_desc.row_pitch;
+        locked_rect->pBits = map_desc.data;
+    }
+    else
+    {
+        locked_rect->Pitch = 0;
+        locked_rect->pBits = NULL;
+    }
 
     return hr;
 }
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c
index a0fcd71..f5afbc4 100644
--- a/dlls/d3d8/tests/device.c
+++ b/dlls/d3d8/tests/device.c
@@ -4039,8 +4039,12 @@ static void test_lockrect_invalid(void)
 
     hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
     ok(SUCCEEDED(hr), "Failed to lock surface with rect NULL, hr %#x.\n", hr);
+    locked_rect.pBits = (void *)0xdeadbeef;
+    locked_rect.Pitch = 1;
     hr = IDirect3DSurface8_LockRect(surface, &locked_rect, NULL, 0);
     ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
+    ok(!locked_rect.pBits, "Got unexpected pBits %p.\n", locked_rect.pBits);
+    ok(!locked_rect.Pitch, "Got unexpected Pitch %u.\n", locked_rect.Pitch);
     hr = IDirect3DSurface8_UnlockRect(surface);
     ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
 
-- 
1.7.10.4




More information about the wine-patches mailing list