Sign in to follow this  

ID3DXMesh cleanup

Recommended Posts

My IDirect3DDevice9 increments its IUnknown ref count (checked via AddRef and Release called in tandem) by 4 after a call to D3DXCreateMesh. Calling Release on the resulting successful mesh immediately following this creation properly decrements the device's ref count by 4. However, calling it later on from a one-stop-shop destruction method of DX9 objects only decrements the device's ref count by 2. All the meshes properly decrement to 0 on Release, but the device maintains 2 * Number Of Meshes extra references and can't itself be released. Any ideas what could be causing this? Also, any ideas what the 4 references actually are? Using the 11/07 SDK...

Share this post

Link to post
Share on other sites
I just tried this myself, and I get 4 AddRef's upon mesh creation and 4 Release's upon releasing the mesh. So I'm not sure why you should only getting 2 releases. As for why there's 4 AddRef's, it's probably like this:

-1 for the vertex buffer
-1 for the index buffer
-1 for the vertex declaration
-1 for the mesh to keep for itself

Make sure you're not calling ID3DXMesh::GetDevice ,ID3DXMesh::GetVertexBuffer or ID3DXMesh::GetIndexBuffer and forgetting to Release something. The first will call AddRef directly on the device, while the other two will call AddRef on the vertex buffer or index buffer interfaces (forgetting to Release these could cause them not to release their own pointer to the device interface).

As a side note, if you have access to ATL and you get tired of managing COM interface pointers I suggest checking out CComPtr. It's a smart pointer class that automatically calls AddRef upon assignment and Release upon new Assignment or going out of scope/deletion.

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