ddraw/tests: Don't crash after a failed CreateSurface() call.
Francois Gouget
fgouget at codeweavers.com
Wed Feb 26 19:46:44 CST 2014
So there are a number of CreateSurface() calls that fail and these are
causing the tests to crash. For instance for ddraw2:
http://test.winehq.org/data/tests/ddraw:ddraw2.html
Is there a way to check what surface types are supported?
create_device() calls EnumDevices() but finding a match clearly does not
guarantee we'll be able to create a surface given the error we get there
(but presumably that check was more for the following CreateDevice()
call). I tried using EnumSurfaces() but without much luck. I'm also a
bit worried that DDENUMSURFACES_MATCH is not used anywhere in Wine (*).
Alternatively we can just react to failing CreateSurface() calls and
clean up + abort a bit like is done in the following patch.
(*) Also the DDENUMSURFACES_{SEARCH,MATCH}TYPE macros found in
dlls/ddraw/ddraw.c are not used anymore since c8901d6f.
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 5a3bd77..2a5a9c4 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -227,7 +227,7 @@ static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD c
surface_desc.dwWidth = 640;
surface_desc.dwHeight = 480;
hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &ds, NULL);
- ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
+ ok(SUCCEEDED(hr) || broken(hr == DDERR_INVALIDPIXELFORMAT), "Failed to create depth buffer, hr %#x.\n", hr);
if (FAILED(hr))
{
IDirect3D2_Release(d3d);
@@ -4451,6 +4451,8 @@ static void test_surface_lock(void)
hr = IDirectDraw2_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, type %s, hr %#x.\n", tests[i].name, hr);
+ if (FAILED(hr))
+ continue;
memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
@@ -4817,6 +4819,8 @@ static void test_set_surface_desc(void)
hr = IDirectDraw2_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ goto done;
hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
ok(SUCCEEDED(hr), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr);
@@ -5113,6 +5117,12 @@ static void test_user_memory_getdc(void)
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
hr = IDirectDraw2_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirectDraw2_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface3, (void **)&surface3);
ok(SUCCEEDED(hr), "Failed to get IDirectDrawSurface3 interface, hr %#x.\n", hr);
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 81c043c..5da4a71 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -5423,6 +5423,12 @@ static void test_set_surface_desc(void)
hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirectDraw4_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
reset_ddsd(&ddsd);
ddsd.dwFlags = DDSD_LPSURFACE;
@@ -5715,6 +5721,12 @@ static void test_user_memory_getdc(void)
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirectDraw4_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
memset(data, 0xaa, sizeof(data));
reset_ddsd(&ddsd);
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 8e01238..4735fca 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -5301,6 +5301,12 @@ static void test_set_surface_desc(void)
hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirectDraw7_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
reset_ddsd(&ddsd);
ddsd.dwFlags = DDSD_LPSURFACE;
@@ -5594,6 +5600,12 @@ static void test_user_memory_getdc(void)
ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY;
hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirectDraw7_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
memset(data, 0xaa, sizeof(data));
reset_ddsd(&ddsd);
More information about the wine-devel
mailing list