[D3D9] fix for SetFVF memleak [2nd try+patch]

Ivan Gyurdiev ivg231 at gmail.com
Sat Oct 7 19:02:35 CDT 2006


Ivan Gyurdiev wrote:
> Karsten Elfenbein wrote:
>> * don't prevent IUnknown_Release of pDecl in the exit section and fix
>> for http://bugs.winehq.org/show_bug.cgi?id=5656
>>   
> This seems wrong, d3d9 does not keep an internal reference of the vdecl.
> Try the attached patch instead, let me know if it works...
>
...better yet, try this one


-------------- next part --------------
---
 dlls/d3d9/d3d9_private.h      |    4 ++++
 dlls/d3d9/device.c            |    3 +++
 dlls/d3d9/vertexdeclaration.c |    6 +++++-
 3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 2d6397e..c5cef9f 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -176,6 +176,10 @@ typedef struct IDirect3DDevice9Impl
     /* IDirect3DDevice9 fields */
     IWineD3DDevice               *WineD3DDevice;
 
+    /* A vertex declaration was converted from setFVF.
+     * Keep track of it, so it can be properly freed */
+    IDirect3DVertexDeclaration9  *convertedDecl;
+
 } IDirect3DDevice9Impl;
 
 
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 6eeaceb..5a836b9 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -60,6 +60,8 @@ static ULONG WINAPI IDirect3DDevice9Impl
     if (ref == 0) {
       IWineD3DDevice_Uninit3D(This->WineD3DDevice);
       IWineD3DDevice_Release(This->WineD3DDevice);
+      if (This->convertedDecl != NULL)
+          IUnknown_Release(This->convertedDecl);
       HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -731,6 +733,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_Se
              
          hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, pDecl);
          if (hr != S_OK) goto exit;
+         This->convertedDecl = pDecl;
          pDecl = NULL;
 
          exit:
diff --git a/dlls/d3d9/vertexdeclaration.c b/dlls/d3d9/vertexdeclaration.c
index 246b52f..88f5909 100644
--- a/dlls/d3d9/vertexdeclaration.c
+++ b/dlls/d3d9/vertexdeclaration.c
@@ -300,8 +300,12 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_Se
     IDirect3DVertexDeclaration9Impl *pDeclImpl = (IDirect3DVertexDeclaration9Impl *)pDecl;
     HRESULT hr = D3D_OK;
 
-    TRACE("(%p) : Relay\n", iface);
+    if (This->convertedDecl && This->convertedDecl != pDecl) {
+        IUnknown_Release(This->convertedDecl);
+        This->convertedDecl = NULL;
+    }
 
+    TRACE("(%p) : Relay\n", iface);
     hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
 
     return hr;
-- 
1.4.2.1



More information about the wine-devel mailing list