Henri Verbeet : d3dx8: Initialize the matrix stack in D3DXCreateMatrixStack ().

Alexandre Julliard julliard at winehq.org
Thu Oct 30 10:10:28 CDT 2008


Module: wine
Branch: master
Commit: bd6a8870e2528244c3cfd5f1d22b411d56dc9bde
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=bd6a8870e2528244c3cfd5f1d22b411d56dc9bde

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Wed Oct 29 16:34:21 2008 +0100

d3dx8: Initialize the matrix stack in D3DXCreateMatrixStack().

Based on a patchset by David Adam.

---

 dlls/d3dx8/d3dx8_private.h |    3 ++-
 dlls/d3dx8/math.c          |   24 +++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/d3dx8_private.h b/dlls/d3dx8/d3dx8_private.h
index 923f285..01174dc 100644
--- a/dlls/d3dx8/d3dx8_private.h
+++ b/dlls/d3dx8/d3dx8_private.h
@@ -86,7 +86,8 @@ struct ID3DXMatrixStackImpl
   LONG                   ref;
 
   /* ID3DXMatrixStack fields */
-  int current;
+  unsigned int current;
+  unsigned int stack_size;
   D3DXMATRIX *stack;
 };
 
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 54a17c2..631f0a1 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -581,10 +581,14 @@ D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *pm)
 
 /*_________________D3DXMatrixStack____________________*/
 
+static const unsigned int INITIAL_STACK_SIZE = 32;
+
 HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack)
 {
     ID3DXMatrixStackImpl* object;
 
+    TRACE("flags %#x, ppstack %p\n", flags, ppstack);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXMatrixStackImpl));
     if ( object == NULL )
     {
@@ -593,7 +597,21 @@ HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack)
     }
     object->lpVtbl = &ID3DXMatrixStack_Vtbl;
     object->ref = 1;
+
+    object->stack = HeapAlloc(GetProcessHeap(), 0, INITIAL_STACK_SIZE * sizeof(D3DXMATRIX));
+    if (!object->stack)
+    {
+        HeapFree(GetProcessHeap(), 0, object);
+        *ppstack = NULL;
+        return E_OUTOFMEMORY;
+    }
+
     object->current = 0;
+    object->stack_size = INITIAL_STACK_SIZE;
+    D3DXMatrixIdentity(&object->stack[0]);
+
+    TRACE("Created matrix stack %p\n", object);
+
     *ppstack = (LPD3DXMATRIXSTACK)object;
     return D3D_OK;
 }
@@ -624,7 +642,11 @@ static ULONG WINAPI ID3DXMatrixStackImpl_Release(ID3DXMatrixStack* iface)
 {
     ID3DXMatrixStackImpl *This = (ID3DXMatrixStackImpl *)iface;
     ULONG ref = InterlockedDecrement(&This->ref);
-    if ( !ref ) HeapFree(GetProcessHeap(), 0, This);
+    if (!ref)
+    {
+        HeapFree(GetProcessHeap(), 0, This->stack);
+        HeapFree(GetProcessHeap(), 0, This);
+    }
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
     return ref;
 }




More information about the wine-cvs mailing list