ID3DXAllocateHierarchy - Memory Leaks

Started by
15 comments, last by John_Idol 16 years, 4 months ago
Hi all, I've been fighting with some memory leaks while loading the mesh. I was able to set the BreakAllocID (it works on my machine at home but doing exactly the same things it doesn't here at work...) on the control panel and looking at the call stack I isolated my last call: HRESULT hr = D3DXLoadMeshHierarchyFromX(filename, D3DXMESH_MANAGED, device, &Alloc, NULL, &m_frameRoot, &m_animController); Does this inequivocally mean that there's something not being freed in the implementation of ID3DXAllocateHierarchy I am using(http://www.toymaker.info/Games/html/load_x_hierarchy.html)? I got the same meory leaks with the demo itself so it's not something I added (I didn't add a thing in the ID3DXAllocateHierarchy implementation). I keep going through the code but I can't find nothing not being freed. My guess would be it is some field populated by the DirectX runtime which I am supposed to free. Shall I post the class cpp? Thanks in advance, JI
Advertisement
Are you calling m_animController->Release() at any point?
Hi Dave,

I am calling

SAFE_RELEASE(m_animController);


which is supposed to be the same thing.

try Bounds Checker, it may be help you find out that problem.
What exactly is bound checker and when can I find it? :-)
check out http://www.compuware.com/products/devpartner/visualc.htm

you can get detail information about it.
Ok, Here we go: this is the implementation I am using, everything looks alright to me.
I am posting just the Create/Destroy frame methods 'cause they're smaller so if anyone is able to find something wrong here i can avoid to post the mesh container stuff (something tells me I am gonna have to...).

struct D3DXFRAME_EXTENDED: public D3DXFRAME{    D3DXMATRIX exCombinedTransformationMatrix;};HRESULT CMeshHierarchy::CreateFrame(LPCSTR Name, LPD3DXFRAME *ppNewFrame){    // Always a good idea to initialise return pointer before proceeding    *ppNewFrame = NULL;	// Create a new frame using the derived version of the structure    D3DXFRAME_EXTENDED *newFrame = new D3DXFRAME_EXTENDED;	ZeroMemory(newFrame,sizeof(D3DXFRAME_EXTENDED));	// Now fill in the data members in the frame structure		// The frame name (note: may be null or zero length)	newFrame->Name=CUtilities::DuplicateCharString(Name);    // Now initialize other data members of the frame to defaults    D3DXMatrixIdentity(&newFrame->TransformationMatrix);    D3DXMatrixIdentity(&newFrame->exCombinedTransformationMatrix);    newFrame->pMeshContainer = NULL;    newFrame->pFrameSibling = NULL;    newFrame->pFrameFirstChild = NULL;	// Assign the return pointer to our newly created frame    *ppNewFrame = newFrame;	    return S_OK;}HRESULT CMeshHierarchy::DestroyFrame(LPD3DXFRAME pFrameToFree) {    // Convert to our extended type. OK as we know for sure it is:    D3DXFRAME_EXTENDED *pFrame = (D3DXFRAME_EXTENDED*)pFrameToFree;    SAFE_DELETE_ARRAY( pFrame->Name );    SAFE_DELETE( pFrame );    return S_OK; }


Thanks!

JI
I'm not 100% sure so this is more a comment but have you checked that the number of frames that you free matches the number that are actually created in the hierarchy?
Fact is I am not calling manually Create/DestryFrame, they're callback methods and I'm just implementing them.
When you load the x file with Hierarchy with D3DXLoadMeshHierarchyFromX everything is managed automatically, so as long as I am deallocating in DestroyFrame everything which is been allocated in CreateFrame it should be fine.

I was hoping someone more experienced than me could spot something I do not see.


Hi do you call DestroyMeshContainer as well.

This topic is closed to new replies.

Advertisement