From bd6a8870e2528244c3cfd5f1d22b411d56dc9bde Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 29 Oct 2008 16:34:21 +0100 Subject: [PATCH] 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 923f2854fa2..01174dcc671 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 54a17c2af69..631f0a1bec0 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; }