D3DX reports 3 unfreed allocations in the following code. I can comment out the code and exit my game and D3DX reports 0 leaks.
I cannot for the life of me find the leaked allocations here. I'm supposing that one or more of the calls increases the ref count. The SDK is sadly lacking in this type of information and gives no indication that these will increase the ref count.
Code:
void X3DMesh::Create(const std::string &File)
{
HRESULT hr = 0;
ID3DXMesh *pTempMesh = 0;
hr = D3DXLoadMeshFromX(File.c_str(),
D3DXMESH_MANAGED,
SpaceXApp::GetInstance()->GetDevice(),
&m_pAdjBuffer,
&m_pMatBuffer,
0,
&m_dwNumMats,
&pTempMesh);
if (FAILED(hr))
{
std::ostringstream ostrm;
ostrm << "Mesh file " << File << " failed to load";
::MessageBox(0,ostrm.str().c_str(),"FILE ERROR",0);
}
//Change vertex format
D3DVERTEXELEMENT9 elems[128];
UINT uNumElements = 0;
VertexPNT1::pDecl->GetDeclaration(elems,&uNumElements);
pTempMesh->CloneMesh(D3DXMESH_SYSTEMMEM,elems,SpaceXApp::GetInstance()->GetDevice(),&m_pMesh);
//Done with temporary mesh
SAFE_RELEASE(pTempMesh);
//Optimize mesh
m_pMesh->GenerateAdjacency(0.05f,(DWORD *)m_pAdjBuffer->GetBufferPointer());
m_pMesh->Optimize(D3DXMESH_MANAGED | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE,
(DWORD *)m_pAdjBuffer->GetBufferPointer(),0,0,0,&m_pMesh);
//Compute bounding sphere and box
D3DXVECTOR3 min_vec,max_vec;
VertexPNT1 *v = 0;
m_pMesh->LockVertexBuffer(0, (void **)&v);
D3DXComputeBoundingBox(&v[0].vecPos,
m_pMesh->GetNumVertices(),
sizeof(VertexPNT1),
&m_MeshBB.minPt,
&m_MeshBB.maxPt);
D3DXComputeBoundingSphere(&v[0].vecPos,
m_pMesh->GetNumVertices(),
sizeof(VertexPNT1),
&m_BSphere.m_vecPos,
&m_BSphere.m_Radius);
m_pMesh->UnlockVertexBuffer();
//Load in materials
if (m_pMatBuffer != 0 && m_dwNumMats != 0)
{
m_pMaterials = new D3DXMATERIAL[m_dwNumMats];
D3DXMATERIAL *pD3DXMats = (D3DXMATERIAL *)m_pMatBuffer->GetBufferPointer();
//TODO
//Pass texture filenames to TextureManager and save off pointers
for (DWORD i = 0;i < m_dwNumMats;++i)
{
m_pMaterials[i].MatD3D.Ambient = pD3DXMats[i].MatD3D.Diffuse;
m_pMaterials[i].MatD3D.Diffuse = pD3DXMats[i].MatD3D.Diffuse;
m_pMaterials[i].MatD3D.Specular = pD3DXMats[i].MatD3D.Specular;
m_pMaterials[i].MatD3D.Power = pD3DXMats[i].MatD3D.Power;
}
}
}
Any help would be appreciated.