Sign in to follow this  
khulad

DirectX 9.0c Memory Leak

Recommended Posts

Hi guys,
I've found what's causing my memory leak (3 allocations not released), if I comment out the line I get no leaks.
The offending line is:
[code]
HR(D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, mMeshShip, adjaceny, &mMeshShip, outAdjaceny, &buffErr));
[/code]

The surrounding code is this:

[code]
DWORD* adjaceny = NULL;
adjaceny = new DWORD[3 * mMeshShip->GetNumFaces() * sizeof(DWORD)];
DWORD* outAdjaceny = NULL;
outAdjaceny = new DWORD[3 * mMeshShip->GetNumFaces() * sizeof(DWORD)];

HR(mMeshShip->GenerateAdjacency(EPSILON, adjaceny));
// Clean the mesh because we'll be performing simplifications
LPD3DXBUFFER buffErr = NULL;
HR(D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, mMeshShip, adjaceny, &mMeshShip, outAdjaceny, &buffErr));
[/code]

Just so you know mMeshShio is a valid mesh.
Any ideas? I've tried placing memory breakpoints on the allocID DirectX suggests (from the debug outpout window) but it never breaks. Like I said if I comment the offending line out I don't get any memory leaks.

Share this post


Link to post
Share on other sites
According to the [url="http://msdn.microsoft.com/en-us/library/bb172719(VS.85).aspx"]documentation[/url] it seems the function creates a new mesh, so you can't just use &mMeshShip to get the output, you must use a separate variable, and then release the old one and replace it with the new one. Also, do you release buffErr if it's non-NULL?

Share this post


Link to post
Share on other sites
Yes I do release buffErr if it isn't non-Null. I can't believe I missed that part of the documentation. I'll make the ammendments now and let you know.
Thankyou.

Share this post


Link to post
Share on other sites
Yep, you was right. :)

This code worked:
[code]
ID3DXMesh* temp = NULL;
HR(D3DXCleanMesh(D3DXCLEAN_SIMPLIFICATION, mMeshShip, adjaceny, &temp, outAdjaceny, &buffErr));
ReleaseCOM(mMeshShip);
mMeshShip = temp;
temp = NULL;
[/code]

I must learn how to read documentation properly. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this