From 9c676e6c19de196ca7501fe940a528927601c420 Mon Sep 17 00:00:00 2001 From: Oliver Stieber Date: Thu, 27 Oct 2005 10:23:41 +0000 Subject: [PATCH] Changed index and vertex buffer so that internal references are counted separately to external ones. --- dlls/d3d8/d3d8_private.h | 10 ++++++++++ dlls/d3d8/device.c | 8 ++++---- dlls/d3d8/indexbuffer.c | 33 +++++++++++++++++++++++++++++++-- dlls/d3d8/vertexbuffer.c | 31 +++++++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index 7f0d928011f..7b92897f715 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -790,6 +790,7 @@ struct IDirect3DVertexBuffer8Impl /* IUnknown fields */ const IDirect3DVertexBuffer8Vtbl *lpVtbl; LONG ref; + LONG refInt; /* IDirect3DResource8 fields */ IDirect3DDevice8Impl *Device; @@ -805,6 +806,10 @@ extern HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT extern ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface); extern ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface); +/* Internal */ +extern ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRefInt(LPDIRECT3DVERTEXBUFFER8 iface); +extern ULONG WINAPI IDirect3DVertexBuffer8Impl_ReleaseInt(LPDIRECT3DVERTEXBUFFER8 iface); + /* IDirect3DVertexBuffer8: (Inherited from IDirect3DResource8) */ extern HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8** ppDevice); extern HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); @@ -838,6 +843,7 @@ struct IDirect3DIndexBuffer8Impl /* IUnknown fields */ const IDirect3DIndexBuffer8Vtbl *lpVtbl; LONG ref; + LONG refInt; /* IDirect3DResource8 fields */ IDirect3DDevice8Impl *Device; @@ -853,6 +859,10 @@ extern HRESULT WINAPI IDirect3DIndexBuffer8Impl_QueryInterface(LPDIRECT3 extern ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface); extern ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface); +/* Internal */ +extern ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRefInt(LPDIRECT3DINDEXBUFFER8 iface); +extern ULONG WINAPI IDirect3DIndexBuffer8Impl_ReleaseInt(LPDIRECT3DINDEXBUFFER8 iface); + /* IDirect3DIndexBuffer8: (Inherited from IDirect3DResource8) */ extern HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8** ppDevice); extern HRESULT WINAPI IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags); diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c index d3503b95ca0..5666317a3f2 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -4164,8 +4164,8 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(LPDIRECT3DDEVICE8 iface, IDirec return D3D_OK; } - if (oldIdxs) IDirect3DIndexBuffer8Impl_Release(oldIdxs); - if (pIndexData) IDirect3DIndexBuffer8Impl_AddRef(This->StateBlock->pIndexData); + if (pIndexData) IDirect3DIndexBuffer8Impl_AddRefInt(This->StateBlock->pIndexData); + if (oldIdxs) IDirect3DIndexBuffer8Impl_ReleaseInt(oldIdxs); return D3D_OK; } HRESULT WINAPI IDirect3DDevice8Impl_GetIndices(LPDIRECT3DDEVICE8 iface, IDirect3DIndexBuffer8** ppIndexData,UINT* pBaseVertexIndex) { @@ -4337,8 +4337,8 @@ HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(LPDIRECT3DDEVICE8 iface, U return D3D_OK; } - if (oldSrc != NULL) IDirect3DVertexBuffer8Impl_Release(oldSrc); - if (pStreamData != NULL) IDirect3DVertexBuffer8Impl_AddRef(pStreamData); + if (pStreamData != NULL) IDirect3DVertexBuffer8Impl_AddRefInt(pStreamData); + if (oldSrc != NULL) IDirect3DVertexBuffer8Impl_ReleaseInt(oldSrc); return D3D_OK; } HRESULT WINAPI IDirect3DDevice8Impl_GetStreamSource(LPDIRECT3DDEVICE8 iface, UINT StreamNumber,IDirect3DVertexBuffer8** pStream,UINT* pStride) { diff --git a/dlls/d3d8/indexbuffer.c b/dlls/d3d8/indexbuffer.c index c865eb66278..2163f2faf4b 100644 --- a/dlls/d3d8/indexbuffer.c +++ b/dlls/d3d8/indexbuffer.c @@ -64,13 +64,42 @@ ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) { TRACE("(%p) : ReleaseRef to %ld\n", This, ref); - if (ref == 0) { + if (ref == 0 && 0 == This->refInt) { + HeapFree(GetProcessHeap(), 0, This->allocatedMemory); + HeapFree(GetProcessHeap(), 0, This); + } else if (0 == ref) { + WARN("(%p) : The application failed to set indicies NULL before releasing the index buffer, leak\n", This); + } + + return ref; +} + + +ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRefInt(LPDIRECT3DINDEXBUFFER8 iface) { + IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface; + ULONG refInt = InterlockedIncrement(&This->refInt); + + TRACE("(%p) : AddRefInt from %ld\n", This, refInt - 1); + + return refInt; +} + +ULONG WINAPI IDirect3DIndexBuffer8Impl_ReleaseInt(LPDIRECT3DINDEXBUFFER8 iface) { + IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface; + ULONG refInt = InterlockedDecrement(&This->refInt); + + TRACE("(%p) : ReleaseRefInt to %ld\n", This, refInt); + + if (0 == This->ref && 0 == refInt) { + WARN("(%p) : Cleaning up after the calling application failed to release the indicies properly\n", This); HeapFree(GetProcessHeap(), 0, This->allocatedMemory); HeapFree(GetProcessHeap(), 0, This); } - return ref; + + return refInt; } + /* IDirect3DResource Interface follow: */ HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8** ppDevice) { IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface; diff --git a/dlls/d3d8/vertexbuffer.c b/dlls/d3d8/vertexbuffer.c index 2c9dbe6a25a..ec17376ba94 100644 --- a/dlls/d3d8/vertexbuffer.c +++ b/dlls/d3d8/vertexbuffer.c @@ -64,11 +64,38 @@ ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) { TRACE("(%p) : ReleaseRef to %ld\n", This, ref); - if (ref == 0) { + if (ref == 0 && 0 == This->refInt) { + HeapFree(GetProcessHeap(), 0, This->allocatedMemory); + HeapFree(GetProcessHeap(), 0, This); + } else if (0 == ref) { + WARN("(%p) : The application failed to set Stream source to NULL before releasing the vertex shader, leak\n", This); + } + + return ref; +} + +ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRefInt(LPDIRECT3DVERTEXBUFFER8 iface) { + IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface; + ULONG refInt = InterlockedIncrement(&This->refInt); + + TRACE("(%p) : AddRefInt from %ld\n", This, refInt - 1); + + return refInt; +} + +ULONG WINAPI IDirect3DVertexBuffer8Impl_ReleaseInt(LPDIRECT3DVERTEXBUFFER8 iface) { + IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface; + ULONG refInt = InterlockedDecrement(&This->refInt); + + TRACE("(%p) : ReleaseRefInt to %ld\n", This, refInt); + + if (0 == This->ref && 0 == refInt) { + WARN("(%p) : Cleaning up after the calling application failed to release the stream source properly\n", This); HeapFree(GetProcessHeap(), 0, This->allocatedMemory); HeapFree(GetProcessHeap(), 0, This); } - return ref; + + return refInt; } /* IDirect3DResource Interface follow: */