Original Post
the program crashs some where in the if(skin) statment the traced my problem using messageBoxes with my marco #define DEBUG_BOX(b) messageBox(b,"Debug",MB_OK); Here is all the relivent code i think would be need i can post more if needed. Problem Line Container CreateContainter Function Notice the commented debug box in the if stament of if( pSkinInfo ) when i uncomment that line the following debug boxes work but the pragm still crashs, but when that line is commented it don't even make it to where the other boxes are, why would a messagebox cause the life of my program extened before crashing and why dose this mesh create contaner crash? can anyone help me? also debuging is out cuase when i run the program with my debuger it don't crash just skips the use of createmeshcontaier all together. [Edited by - alex_dergian on December 22, 2005 9:50:56 PM]
// If there is skin data associated with the mesh copy it over
if( pSkinInfo )
{
// Get the SkinInfo
newMeshContainer->pSkinInfo = pSkinInfo;
if( pSkinInfo == NULL )
{
DEBUG_BOX("Invalade skin data");
return E_INVALIDARG;
}
// first save off the SkinInfo and original mesh data
pSkinInfo->AddRef();
//DEBUG_BOX("Pre-Error");
// Will need an array of offset matrices to move the vertices from the figure space to the
// bone's space
const DWORD NumBones = pSkinInfo->GetNumBones();
DEBUG_BOX("Pre-Error");
pNewBoneOffsetMatrices = new D3DXMATRIX[ NumBones ];
DEBUG_BOX("Pre-Error");
if( NULL == pNewBoneOffsetMatrices )
{
DEBUG_BOX("Out of memory, creating matrix");
return E_OUTOFMEMORY;
}
DEBUG_BOX("Pre-Error");
// Get each of the bone offset matrices so that we don't need to get them later
for( UINT iBone = 0; iBone < NumBones; iBone++ )
{
DEBUG_BOX("Placing bone");
pNewBoneOffsetMatrices[iBone] = *(pSkinInfo->GetBoneOffsetMatrix(iBone));
}
DEBUG_BOX("Post-Error");
// Copy the pointer
newMeshContainer->m_boneOffsets = pNewBoneOffsetMatrices;
pNewBoneOffsetMatrices = NULL;
// GenerateSkinnedMesh will take the general skinning information and transform it to a
// HW friendly version
// Save off the mesh
ID3DXMesh* pMeshStart = newMeshContainer->MeshData.pMesh;
newMeshContainer->MeshData.pMesh = NULL;
// Use ConvertToIndexedBlendedMesh to generate drawable mesh
newMeshContainer->m_dNumPaletteEntries = pSkinInfo->GetNumBones();
pSkinInfo->ConvertToIndexedBlendedMesh( pMeshStart,
D3DXMESHOPT_VERTEXCACHE | D3DXMESH_MANAGED,
newMeshContainer->m_dNumPaletteEntries,
newMeshContainer->pAdjacency,
NULL, NULL, NULL,
newMeshContainer->m_dMaxNumFaceInfls,
newMeshContainer->m_dNumAttrGroups,
newMeshContainer->m_pBufBoneCombos,
&newMeshContainer->MeshData.pMesh );
}
else
{
// No skin info so null all the pointers
newMeshContainer->pSkinInfo = NULL;
newMeshContainer->m_boneOffsets = NULL;
newMeshContainer->m_skinMesh = NULL;
newMeshContainer->m_bonePointers = NULL;
}
struct myMeshContainer : public D3DXMESHCONTAINER
{
//Mesh Propertys
LPDIRECT3DTEXTURE9 *m_pTextures;
D3DMATERIAL9 *m_pMaterials;
LPD3DXMESH m_pWorkingMesh;
//Skinning Propertys
ID3DXMesh* m_skinMesh;
D3DXMATRIX * m_boneOffsets; // Bone offset matrices retrieved from pSkinInfo
D3DXMATRIX ** m_bonePointers; // Provides index to bone matrix lookup
//Skinning HW acceleration varables
DWORD m_dNumPaletteEntries;
DWORD *m_dMaxNumFaceInfls;
DWORD *m_dNumAttrGroups;
LPD3DXBUFFER *m_pBufBoneCombos;
};
HRESULT myMeshAllocateHierarchy::CreateMeshContainer( THIS_ LPCSTR Name,CONST D3DXMESHDATA *pMeshData,
CONST D3DXMATERIAL *pMaterials,CONST D3DXEFFECTINSTANCE *pEffectInstances,
DWORD NumMaterials,CONST DWORD *pAdjacency,LPD3DXSKININFO pSkinInfo,
LPD3DXMESHCONTAINER* ppNewMeshContainer)
{
//initalize data
D3DXMATRIX* pNewBoneOffsetMatrices = NULL;
//Create a mesh container structure to fill and initilaise to zero values
myMeshContainer *newMeshContainer=new myMeshContainer;
if( newMeshContainer == NULL )
DEBUG_BOX("Out of memeory in contoaner");
ZeroMemory(newMeshContainer, sizeof(myMeshContainer));
//Set the output mesh container to our newly created one
*ppNewMeshContainer = newMeshContainer;
//The mesh type
if (pMeshData->Type!=D3DXMESHTYPE_MESH)
{
// This does not handle mesh types other than the standard
DestroyMeshContainer(newMeshContainer);
return E_FAIL;
}
if(Name)
{
// Put in the name
int nNameSize = strlen(Name)+1;
newMeshContainer->Name = new char[nNameSize];
memcpy(newMeshContainer->Name, Name, nNameSize*sizeof(char));
}
else
newMeshContainer->Name = NULL;
newMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;
// Adjacency data - holds information about triangle adjacency, required by the ID3DMESH object
DWORD dwFaces = pMeshData->pMesh->GetNumFaces();
newMeshContainer->pAdjacency = new DWORD[dwFaces*3];
memcpy(newMeshContainer->pAdjacency, pAdjacency, sizeof(DWORD) * dwFaces*3);
// Get the Direct3D device, luckily this is held in the mesh itself
LPDIRECT3DDEVICE9 pd3dDevice = NULL;
pMeshData->pMesh->GetDevice(&pd3dDevice);
// Make a copy of the mesh data that is passed in and place it in our mesh container
D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE];
if (FAILED(pMeshData->pMesh->GetDeclaration(Declaration)))
return E_FAIL;
//pMeshData->pMesh->CloneMeshFVF(D3DXMESH_MANAGED,
// pMeshData->pMesh->GetFVF(), pd3dDevice,
// &newMeshContainer->MeshData.pMesh);
pMeshData->pMesh->CloneMesh(D3DXMESH_MANAGED,
Declaration, pd3dDevice,
&newMeshContainer->MeshData.pMesh);
// Create material and texture arrays. Note that I always want to have at least one
newMeshContainer->NumMaterials = NumMaterials;
newMeshContainer->m_pMaterials = new D3DMATERIAL9[newMeshContainer->NumMaterials];
newMeshContainer->m_pTextures = new LPDIRECT3DTEXTURE9[newMeshContainer->NumMaterials];
ZeroMemory(newMeshContainer->m_pTextures, sizeof(LPDIRECT3DTEXTURE9) * newMeshContainer->NumMaterials);
if (NumMaterials>0)
{
// Load all the textures and copy the materials over
for(DWORD i = 0; i < NumMaterials; ++i)
{
newMeshContainer->m_pTextures = NULL;
newMeshContainer->m_pMaterials=pMaterials.MatD3D;
if(pMaterials.pTextureFilename)
{
// Use the D3DX function to create the texturer
if(FAILED(D3DXCreateTextureFromFile(pd3dDevice, pMaterials.pTextureFilename,&newMeshContainer->m_pTextures)))
{
newMeshContainer->m_pTextures = NULL;
}
}
}
}
else
// make a default material in the case where the mesh did not come with one
{
ZeroMemory(&newMeshContainer->m_pMaterials[0], sizeof( D3DMATERIAL9 ) );
newMeshContainer->m_pMaterials[0].Diffuse.r = 0.5f;
newMeshContainer->m_pMaterials[0].Diffuse.g = 0.5f;
newMeshContainer->m_pMaterials[0].Diffuse.b = 0.5f;
newMeshContainer->m_pMaterials[0].Specular = newMeshContainer->m_pMaterials[0].Diffuse;
newMeshContainer->m_pTextures[0]=NULL;
}
// If there is skin data associated with the mesh copy it over
if( pSkinInfo )
{
// Get the SkinInfo
newMeshContainer->pSkinInfo = pSkinInfo;
if( pSkinInfo == NULL )
{
DEBUG_BOX("Invalade skin data");
return E_INVALIDARG;
}
// first save off the SkinInfo and original mesh data
pSkinInfo->AddRef();
//DEBUG_BOX("Pre-Error");
// Will need an array of offset matrices to move the vertices from the figure space to the
// bone's space
const DWORD NumBones = pSkinInfo->GetNumBones();
DEBUG_BOX("Pre-Error");
pNewBoneOffsetMatrices = new D3DXMATRIX[ NumBones ];
DEBUG_BOX("Pre-Error");
if( NULL == pNewBoneOffsetMatrices )
{
DEBUG_BOX("Out of memory, creating matrix");
return E_OUTOFMEMORY;
}
DEBUG_BOX("Pre-Error");
// Get each of the bone offset matrices so that we don't need to get them later
for( UINT iBone = 0; iBone < NumBones; iBone++ )
{
DEBUG_BOX("Placing bone");
pNewBoneOffsetMatrices[iBone] = *(pSkinInfo->GetBoneOffsetMatrix(iBone));
}
DEBUG_BOX("Post-Error");
// Copy the pointer
newMeshContainer->m_boneOffsets = pNewBoneOffsetMatrices;
pNewBoneOffsetMatrices = NULL;
// GenerateSkinnedMesh will take the general skinning information and transform it to a
// HW friendly version
// Save off the mesh
ID3DXMesh* pMeshStart = newMeshContainer->MeshData.pMesh;
newMeshContainer->MeshData.pMesh = NULL;
// Use ConvertToIndexedBlendedMesh to generate drawable mesh
newMeshContainer->m_dNumPaletteEntries = pSkinInfo->GetNumBones();
pSkinInfo->ConvertToIndexedBlendedMesh( pMeshStart,
D3DXMESHOPT_VERTEXCACHE | D3DXMESH_MANAGED,
newMeshContainer->m_dNumPaletteEntries,
newMeshContainer->pAdjacency,
NULL, NULL, NULL,
newMeshContainer->m_dMaxNumFaceInfls,
newMeshContainer->m_dNumAttrGroups,
newMeshContainer->m_pBufBoneCombos,
&newMeshContainer->MeshData.pMesh );
}
else
{
// No skin info so null all the pointers
newMeshContainer->pSkinInfo = NULL;
newMeshContainer->m_boneOffsets = NULL;
newMeshContainer->m_skinMesh = NULL;
newMeshContainer->m_bonePointers = NULL;
}
DEBUG_BOX("Affter Skinning");
// When we got the device we caused an internal reference count to be incremented
// So we now need to release it
DEBUG_BOX("Before need relise");
OK_REL_PNT(pd3dDevice);
DEBUG_BOX("Device Realised");
// The mesh may contain a reference to an effect file
if (pEffectInstances)
{
DEBUG_BOX("There is a effect");
if (pEffectInstances->pEffectFilename)
{
DEBUG_BOX("It wants to set");
}
}
DEBUG_BOX("Beyoned effects");
DEBUG_BOX("contanor set");
return S_OK;
}