[SOLVED]Strange memory leaks

Started by
1 comment, last by b3rs3rk 17 years, 4 months ago
i've found some strange memory leaks:

bool CModel::OptimizeMesh(LPD3DXMESH *lpMesh){ 
	HRESULT hr = S_OK;

	DWORD *pAdjacencyIn = NULL;
	LPD3DXMESH tMesh = *lpMesh;
	pAdjacencyIn = new DWORD[tMesh->GetNumFaces()*sizeof(DWORD)*3];

	hr = tMesh->GenerateAdjacency(1e-6f, pAdjacencyIn); 
	if( FAILED(hr) )
		return false;

	hr = D3DXCleanMesh( D3DXCLEAN_SIMPLIFICATION  , tMesh, pAdjacencyIn, &tMesh, pAdjacencyIn, NULL);
	if( FAILED(hr) )
		return false;

	SAFE_DELETE(pAdjacencyIn);

	return true;
}



if i comment out D3DXCleanMesh, there are no leaks. This is the output at the end of the program: The thread 'Win32 Thread' (0xa4) has exited with code 0 (0x0). D3DX: MEMORY LEAKS DETECTED: 2 allocations unfreed (5436 bytes) Any advices? [Edited by - b3rs3rk on December 12, 2006 8:17:54 AM]
Advertisement
I would suggest wrapping all of the COM interfaces you use from DirectX in a com pointer. CComPtr will manage the reference counting of the interfaces automagically.

#include <atlbase.h>CComPtr<IDirect3DVertexBuffer9> Direct3DVertexBufferetc...


Dave
changed to bool CModel::OptimizeMesh(CComPtr<ID3DXMesh> lpMesh)
now works, thanks :D

This topic is closed to new replies.

Advertisement