From c53487b599a50ddcf0311ffe4be456975f984cbb Mon Sep 17 00:00:00 2001 From: David Hedberg Date: Mon, 3 Sep 2007 13:57:24 +0200 Subject: [PATCH] ddraw: Fix and test case for situation where DDSD_MIPMAPCOUNT is set and dwMipMapCount is 0. --- dlls/ddraw/ddraw.c | 7 ++++++- dlls/ddraw/tests/dsurface.c | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 696552d4fa..7c6bf5f8ac 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -2417,7 +2417,12 @@ IDirectDrawImpl_CreateSurface(IDirectDraw7 *iface, { if(desc2.dwFlags & DDSD_MIPMAPCOUNT) { - /* Mipmap count is given, nothing to do */ + /* Mipmap count is given, should not be 0 */ + if( desc2.u2.dwMipMapCount == 0 ) + { + LeaveCriticalSection(&ddraw_cs); + return DDERR_INVALIDPARAMS; + } } else { diff --git a/dlls/ddraw/tests/dsurface.c b/dlls/ddraw/tests/dsurface.c index 6c223f4e85..59fd4ae020 100644 --- a/dlls/ddraw/tests/dsurface.c +++ b/dlls/ddraw/tests/dsurface.c @@ -183,6 +183,25 @@ static void MipMapCreationTest(void) /* Destroy the surface. */ IDirectDrawSurface_Release(lpDDSMipMapTest); + + + /* Fifth mipmap creation test: try to create a surface with + DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, DDSD_MIPMAPCOUNT, + where dwMipMapCount = 0. This should fail. */ + + ddsd.dwSize = sizeof(ddsd); + ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT; + ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP; + U2(ddsd).dwMipMapCount = 0; + ddsd.dwWidth = 128; + ddsd.dwHeight = 32; + rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL); + ok(rc==DDERR_INVALIDPARAMS,"CreateSurface returned: %x\n",rc); + + /* Destroy the surface. */ + if( rc == DD_OK ) + IDirectDrawSurface_Release(lpDDSMipMapTest); + } static void SrcColorKey32BlitTest(void) -- 2.32.0.93.g670b81a890