Sign in to follow this  

Proper way to release mesh objects created with D3DXCreateMeshFVF?

Recommended Posts

I am creating an array of meshes and then rendering them. This I have no problem with :)
But if I try and release/delete the meshes on program exit I get a nasty crash and if I don't release/delete I get memory leaks.
Below is some code snippets.


// Create an empty starting mesh
if(FAILED(D3DXCreateMeshFVF(nStrips * 2, (nStrips * 2) + 2, D3DXMESH_MANAGED, CD3DBase::FVF, pD3DDevice, &pMesh)))
return false;


delete m_pGameTerrain;
delete m_pGameCamera;



for(std::vector<LPD3DXMESH>::iterator it = m_vMeshes.begin(); it != m_vMeshes.end(); ++it)

Any suggestions what is wrong? I can provide more code if necessary but I am sure that wouldn't be relevant;

p.s. how do you make a code block in a post? [ code ] and [ /code ] don't seem to work.

Share this post

Link to post
Share on other sites
Does the Debug Runtime give you any information?

What does "nasty crash" mean? If you get error messages, what are they?

What does Reset() do, and why?

Do you release pD3DDevice anywhere?

EDIT: it appears you have the code blocks correct, though you can put all the code within one block.

Share this post

Link to post
Share on other sites
Sorry for the late reply but I didn't get email notification of a reply =/

I continued on and just removed the (*it)->Release(); code for now.

While adding texture coords and removing colour, I remmed out the code where I was locking the vertex and index buffers and making my mesh and decided to put back the (*it)->Release(); code. Strangely enough the code worked as it should do!

As a conclusion there must be something I am doing wrong in my lock/unlock or vertex/index assign code and causing a buffer overrun!

Thanks anyway ;)

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