Properly releasing LPD3DXMESH

Started by
10 comments, last by circlesoft 19 years, 9 months ago
I just noticed in the DX9 examples that all they do to release a mesh (or invalidate it) is to do a SAFE_RELEASE( m_pLocalMesh ); call and that's it. I thought you would also need to do a Release or SAFE_RELEASE for all the model's materials and textures, or is that done automatically by releasing the mesh?
Advertisement
No, you also need to release all the textures, as well. The ID3DXMesh interface doesn't actually know anything about the textures, besides the filenames.

Here is what you should be doing:
(1) For each texture:
 (a) texture->Release();
(2) mesh->Release();

When I get home, I'll check out the SDK samples and find out exactly what they are doing.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Should I also delete or SAFE_DELETE the textures? or is that overkill or something that the release already did? And what about the D3DMATERIAL9's for the Mesh, does that need to be released and deleted?
Textures should be released, but not materials.
In general, when in doubt, check it out in sdk docs. If clas interface have Release() function, its is a sign that it would be good thing to release it.

Retriving lost device is a good way to find out if you release all that should be released...

Try to write releasing/retriving device code. Its good thing to do at the beggining. I did it when my project had over 10000 lines.. and it was hell.
Greetings!

When dealing with .X files you should release/delete:
- Hiererchy Frames
- Material buffers
- Textures
- Mesh itself

You may help yourself with _CrtOutputDebugString() it will tell you if your code is not released complete. If you have doubt's what to release, try FIRST SAFE_RELEASE( somethin' ) and if it fails, then go to SAFE_DELETE or SAFE_DELETE_ARRAY. Everything can be deleted, but not everything can be released. So there's the point. If you release someting that can be relesed it's done, if you can't release it, it's just some kind of buffer so delete it. Vioala. Pay attention with the 6th tutorial in MS DX Summer update SDK for Direct3D. There is it explained.
Quote:Original post by nPawn
Should I also delete or SAFE_DELETE the textures?

Quote:Original post by AP
If you have doubt's what to release, try FIRST SAFE_RELEASE( somethin' ) and if it fails, then go to SAFE_DELETE or SAFE_DELETE_ARRAY. Everything can be deleted, but not everything can be released.
It's simple - all DirectX interfaces are released - not deleted! Release() automatically deletes the objects. This actually originates from IUnknown and COM. For example, these interfaces need to be released (not deleted):
IDirect3D9IDirect3D9IDirect3DBaseTexture9IDirect3DCubeTexture9IDirect3DDevice9IDirect3DIndexBuffer9IDirect3DPixelShader9IDirect3DQuery9IDirect3DResource9IDirect3DStateBlock9IDirect3DSurface9IDirect3DSwapChain9IDirect3DTexture9IDirect3DVertexBuffer9IDirect3DVertexDeclaration9IDirect3DVertexShader9IDirect3DVolume9IDirect3DVolumeTexture9ID3DXAllocateHierarchyID3DXAnimationCallbackHandlerID3DXAnimationControllerID3DXAnimationSetID3DXBaseEffectID3DXBaseMeshID3DXBufferID3DXCompressedAnimationSetID3DXConstantTableID3DXEffectID3DXEffectCompilerID3DXEffectPoolID3DXEffectStateManagerID3DXFontID3DXFragmentLinkerID3DXIncludeID3DXKeyframedAnimationSetID3DXLineID3DXLoadUserDataID3DXMatrixStackID3DXMeshID3DXPatchMeshID3DXPMeshID3DXRenderToEnvMapID3DXRenderToSurfaceID3DXSaveUserDataID3DXSkinInfoID3DXSPMeshID3DXSprite

As you can see, this is all D3D and D3DX interfaces. If you get instantiate it from Direct3D or D3DX and it starts with an 'I' or 'LP', then it needs to be released.

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Ok, one last question (hopefully =)

Some of these items like ID3DXFont and ID3DXSprite have an OnLostDevice function. Should I call that function when resetting a lost device, then Release the item (or in the opposite order?), or is OnLostDevice good enough?
When you have to reset the device, this is what you should do:
ResetDevice(){  // On lost device comes first  ID3DXSprite::OnLostDevice()  ID3DXFont::OnLostDevice()  ...  // Reset device  IDirect3DDevice9::Reset()  // On reset device comes after  ID3DXSprite::OnResetDevice()  ID3DXFont::OnResetDevice()}
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
So let me get this straight for the special cases that have the OnLostDevice like D3DXSprite


device is lost (alt tab or something)
device is able to be reset now
pSprite->OnLostDevice()
device is reset()
pSprite->OnResetDevice()


No Release() call is needed for the pSprite in this case, and there's no need to reload the texture and stuff for it?

[Edited by - nPawn on July 7, 2004 4:05:19 PM]
Quote:Original post by nPawn
device is lost (alt tab or something)
device is able to be reset now
pSprite->OnLostDevice()
device is reset()
pSprite->OnResetDevice()

That is correct.
Quote:Original post by nPawn
No Release() call is needed for the pSprite in this case, and there's no need to reload the texture and stuff for it?

If the texture was created in the D3DPOOL_DEFAULT memory pool, then it must be reloaded. If it was created in D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM, then it doesn't have to be.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

This topic is closed to new replies.

Advertisement