Signed-off-by: Sven Baars sbaars@codeweavers.com --- v2: Add a missing return value test (thanks Gijs!).
dlls/d3dx9_36/sprite.c | 18 ++++++++++++------ dlls/d3dx9_36/tests/core.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/dlls/d3dx9_36/sprite.c b/dlls/d3dx9_36/sprite.c index 9ef7f9c47e0..cd244e657ef 100644 --- a/dlls/d3dx9_36/sprite.c +++ b/dlls/d3dx9_36/sprite.c @@ -112,10 +112,13 @@ static ULONG WINAPI d3dx9_sprite_Release(ID3DXSprite *iface) { int i;
- for (i = 0; i < sprite->sprite_count; ++i) + if (!(sprite->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE)) { - if (sprite->sprites[i].texture) - IDirect3DTexture9_Release(sprite->sprites[i].texture); + for (i = 0; i < sprite->sprite_count; ++i) + { + if (sprite->sprites[i].texture) + IDirect3DTexture9_Release(sprite->sprites[i].texture); + } }
HeapFree(GetProcessHeap(), 0, sprite->sprites); @@ -518,10 +521,13 @@ static HRESULT WINAPI d3dx9_sprite_OnResetDevice(ID3DXSprite *iface)
TRACE("iface %p.\n", iface);
- for (i = 0; i < sprite->sprite_count; ++i) + if (!(sprite->flags & D3DXSPRITE_DO_NOT_ADDREF_TEXTURE)) { - if (sprite->sprites[i].texture) - IDirect3DTexture9_Release(sprite->sprites[i].texture); + for (i = 0; i < sprite->sprite_count; ++i) + { + if (sprite->sprites[i].texture) + IDirect3DTexture9_Release(sprite->sprites[i].texture); + } }
sprite->sprite_count = 0; diff --git a/dlls/d3dx9_36/tests/core.c b/dlls/d3dx9_36/tests/core.c index 020f18e622c..a8477591e87 100644 --- a/dlls/d3dx9_36/tests/core.c +++ b/dlls/d3dx9_36/tests/core.c @@ -306,6 +306,20 @@ static void test_ID3DXSprite(IDirect3DDevice9 *device) hr = ID3DXSprite_End(sprite); ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
+ /* Test D3DXSPRITE_DO_NOT_ADDREF_TEXTURE */ + hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_DO_NOT_ADDREF_TEXTURE); + ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); + hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); + ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); + hr = ID3DXSprite_OnResetDevice(sprite); + ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK); + check_ref((IUnknown*)tex2, 1); + + hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_DO_NOT_ADDREF_TEXTURE); + ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK); + hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255)); + ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK); + IDirect3DDevice9_EndScene(device); check_release((IUnknown*)sprite, 0); check_release((IUnknown*)tex2, 0);