• Advertisement
Sign in to follow this  

ID3DXMesh cleanup

This topic is 3644 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

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
Advertisement
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
Besides, the values returned from the AddRef() and Release() functions are not reliable. You should really just trust Direct3D to clean up after itself.

Share this post


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

  • Advertisement