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

Ivan Gyurdiev ivg231 at gmail.com
Sat Oct 7 18:53:12 CDT 2006


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...

-------------- next part --------------
---
 dlls/d3d9/d3d9_private.h      |    4 ++++
 dlls/d3d9/device.c            |    1 +
 dlls/d3d9/vertexdeclaration.c |    6 +++++-
 3 files changed, 10 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..185a7ef 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -731,6 +731,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