d3d9: Do not decrease swapchain surface refcount when it is already 0.

Based on a patch by Henri Verbeet.

Signed-off-by: Józef Kucia <jkucia@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Józef Kucia 2017-02-13 13:07:34 +01:00 committed by Alexandre Julliard
parent 94fab4cf1a
commit d39630fc39
2 changed files with 22 additions and 6 deletions

View File

@ -91,6 +91,12 @@ static ULONG WINAPI d3d9_surface_Release(IDirect3DSurface9 *iface)
return IDirect3DBaseTexture9_Release(&surface->texture->IDirect3DBaseTexture9_iface);
}
if (!surface->resource.refcount)
{
WARN("Surface does not have any references.\n");
return 0;
}
refcount = InterlockedDecrement(&surface->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);

View File

@ -1464,6 +1464,8 @@ static void test_refcount(void)
CHECK_REFCOUNT(device, ++refcount);
CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
CHECK_REFCOUNT(device, --refcount);
CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
CHECK_RELEASE_REFCOUNT(pRenderTarget, 0);
}
/* Render target and back buffer are identical. */
@ -1474,6 +1476,8 @@ static void test_refcount(void)
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
ok(pRenderTarget == pBackBuffer, "RenderTarget=%p and BackBuffer=%p should be the same.\n",
pRenderTarget, pBackBuffer);
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
pBackBuffer = NULL;
}
CHECK_REFCOUNT(device, --refcount);
@ -1499,6 +1503,8 @@ static void test_refcount(void)
CHECK_REFCOUNT(device, ++refcount);
CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
CHECK_REFCOUNT(device, --refcount);
CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
CHECK_RELEASE_REFCOUNT(pStencilSurface, 0);
pStencilSurface = NULL;
}
@ -1653,6 +1659,8 @@ static void test_refcount(void)
CHECK_REFCOUNT(device, ++refcount);
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
CHECK_REFCOUNT(device, --refcount);
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
CHECK_RELEASE_REFCOUNT(pBackBuffer, 0);
pBackBuffer = NULL;
}
CHECK_REFCOUNT( pSwapChain, 1);
@ -1675,6 +1683,8 @@ static void test_refcount(void)
ok(pRenderTarget == pRenderTarget2, "RenderTarget=%p and RenderTarget2=%p should be the same.\n",
pRenderTarget, pRenderTarget2);
CHECK_REFCOUNT(device, --refcount);
CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
CHECK_RELEASE_REFCOUNT(pRenderTarget2, 0);
pRenderTarget2 = NULL;
}
pRenderTarget = NULL;