Jump to content
  • Advertisement
Sign in to follow this  
John_Idol

ID3DXAllocateHierarchy - Memory Leaks

This topic is 3880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!