Sign in to follow this  

Mesh exported with Skinweights has problems

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

Just don't know where to start attacking the bug...

First-chance exception at 0x7697c41f (KernelBase.dll) in PerfectSim.exe: Microsoft C++ exception: char at memory location 0x00502edc..
#include "CMesh.h"

HRESULT CAllocateHierarchy::CreateFrame(LPCSTR Name, LPD3DXFRAME *ppNewFrame)
{	
	*ppNewFrame = NULL;

	FRAME *pFrame = new FRAME;

	if(Name != NULL)
	{
		pFrame->Name = new TCHAR[strlen(Name) + 1];
		strcpy((char*)pFrame->Name, (const char*)Name);
	}
	else
	{
		pFrame->Name = new TCHAR[10];
		strcpy((char*)pFrame->Name, "Unnamed");
	}

	// initialize other data members of the frame
	D3DXMatrixIdentity(&pFrame->TransformationMatrix);
	D3DXMatrixIdentity(&pFrame->matCombined);

	pFrame->pMeshContainer = NULL;
	pFrame->pFrameSibling = NULL;
	pFrame->pFrameFirstChild = NULL;

	*ppNewFrame = pFrame;
	pFrame = NULL;

	return S_OK;
}

HRESULT CAllocateHierarchy::CreateMeshContainer(LPCSTR Name,
						CONST D3DXMESHDATA *pMeshData,
						CONST D3DXMATERIAL *pMaterials,
						CONST D3DXEFFECTINSTANCE *pEffectInstances,
						DWORD NumMaterials,
						CONST DWORD *pAdjacency,
						LPD3DXSKININFO pSkinInfo,
						LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
	*ppNewMeshContainer = NULL;

	MESHCONTAINER *pMeshContainer = new MESHCONTAINER;	
	ZeroMemory(pMeshContainer, sizeof(MESHCONTAINER));

	// get device
	LPDIRECT3DDEVICE9 pDevice;
	pMeshData->pMesh->GetDevice(&pDevice);


	if(Name != NULL)
	{
		pMeshContainer->Name = new TCHAR[strlen(Name) + 1];
		strcpy((char*)pMeshContainer->Name, (const char*)Name);
	}
	else
	{
		pMeshContainer->Name = new TCHAR[10];
		strcpy((char*)pMeshContainer->Name, "Unnamed");
	}

	// store mesh
	pMeshContainer->MeshData.Type = D3DXMESHTYPE_MESH;	
	 // if no normals are in the mesh, add them
    if (!(pMeshData->pMesh->GetFVF() & D3DFVF_NORMAL))
    {
        // clone the mesh to make room for the normals
        pMeshData->pMesh->CloneMeshFVF( pMeshData->pMesh->GetOptions(), 
                                    pMeshData->pMesh->GetFVF() | D3DFVF_NORMAL, 
                                    pDevice, &pMeshContainer->MeshData.pMesh );


        // now generate the normals for the pmesh
        D3DXComputeNormals( pMeshContainer->MeshData.pMesh, NULL );
    }
    else  // if no normals, just add a reference to the mesh for the mesh container
    {
		pMeshContainer->MeshData.pMesh = pMeshData->pMesh;		
		pMeshContainer->MeshData.pMesh->AddRef();
    }	

	DWORD dwNumFaces = pMeshData->pMesh->GetNumFaces();

	// allocate memory to contain the material information.  This sample uses
	// the D3D9 materials and texture names instead of the EffectInstance style materials
	pMeshContainer->NumMaterials = max(1, NumMaterials);
	pMeshContainer->pMaterials = new D3DXMATERIAL[pMeshContainer->NumMaterials];
	pMeshContainer->ppTextures = new LPDIRECT3DTEXTURE9[pMeshContainer->NumMaterials];
	pMeshContainer->pAdjacency = new DWORD[dwNumFaces * 3];

	memcpy(pMeshContainer->pAdjacency, pAdjacency, sizeof(DWORD) * dwNumFaces * 3);
	memset(pMeshContainer->ppTextures, 0, sizeof(LPDIRECT3DTEXTURE9) * pMeshContainer->NumMaterials);

	// if materials provided, copy them
	if (NumMaterials > 0)            
	{
		memcpy(pMeshContainer->pMaterials, pMaterials, sizeof(D3DXMATERIAL) * NumMaterials);
		// copy ambient color
//		pMeshContainer->pMaterials->MatD3D.Ambient = 
//			pMeshContainer->pMaterials->MatD3D.Diffuse;

		for (int iMaterial = 0; iMaterial < NumMaterials; iMaterial++)
		{
			if (pMeshContainer->pMaterials[iMaterial].pTextureFilename != NULL)
			{
				// store the texture filename instead, 
				// we will load the texture later on the GenerateSkinnedMesh function
				// so we could append the texture path
				pMeshContainer->pMaterials[iMaterial].pTextureFilename = new char[strlen(pMaterials[iMaterial].pTextureFilename) + 1];
				strcpy(pMeshContainer->pMaterials[iMaterial].pTextureFilename, pMaterials[iMaterial].pTextureFilename);
			}
		}
	}
	else // if no materials provided, use a default one
	{
		pMeshContainer->pMaterials[0].pTextureFilename = NULL;
		memset(&pMeshContainer->pMaterials[0].MatD3D, 0, sizeof(D3DMATERIAL9));		
		pMeshContainer->pMaterials[0].MatD3D.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	}

	// if there is skinning information, save off the required data and then setup for HW skinning
	if (pSkinInfo != NULL)
	{
		// first save off the SkinInfo and original mesh data
		pMeshContainer->pSkinInfo = pSkinInfo;
		pMeshContainer->pSkinInfo->AddRef();

		pMeshContainer->pOrigMesh = pMeshData->pMesh;
		pMeshContainer->pOrigMesh->AddRef();        

		// Will need an array of offset matrices to move the vertices from the figure space to the bone's space
		DWORD dwNumBones = pSkinInfo->GetNumBones();
		pMeshContainer->pBoneOffsetMatrices = new D3DXMATRIX[dwNumBones];

		// get each of the bone offset matrices so that we don't need to get them later
		for (DWORD iBone = 0; iBone < dwNumBones; iBone++)
		{
			pMeshContainer->pBoneOffsetMatrices[iBone] = *(pMeshContainer->pSkinInfo->GetBoneOffsetMatrix(iBone));
		}
	}

	*ppNewMeshContainer = pMeshContainer;
	pMeshContainer = NULL;

	pDevice->Release();
	pDevice = NULL;

	return S_OK;
}

HRESULT CAllocateHierarchy::DestroyFrame(LPD3DXFRAME pFrameToFree)
{	
	delete [] pFrameToFree->Name;
	pFrameToFree->Name = NULL;

	delete pFrameToFree;
	pFrameToFree = NULL;

	return S_OK;
}

#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }

HRESULT CAllocateHierarchy::DestroyMeshContainer(LPD3DXMESHCONTAINER pMeshContainerBase)
{
	UINT iMaterial;
	MESHCONTAINER *pMeshContainer = (MESHCONTAINER*)pMeshContainerBase;

	SAFE_DELETE_ARRAY( pMeshContainer->Name );
	SAFE_DELETE_ARRAY( pMeshContainer->pAdjacency );
	SAFE_DELETE_ARRAY( pMeshContainer->pMaterials );
	SAFE_DELETE_ARRAY( pMeshContainer->pBoneOffsetMatrices );

	// release all the allocated textures
	if (pMeshContainer->ppTextures != NULL)
		for (iMaterial = 0; iMaterial < pMeshContainer->NumMaterials; iMaterial++)
			SAFE_RELEASE( pMeshContainer->ppTextures[iMaterial] );

	// not found in skinned mesh
	SAFE_DELETE_ARRAY(pMeshContainer->pAttributeTable);
	SAFE_DELETE_ARRAY( pMeshContainer->pBoneMatrices );

	SAFE_DELETE_ARRAY( pMeshContainer->ppTextures );
	SAFE_DELETE_ARRAY( pMeshContainer->ppBoneMatrixPtrs );	
	SAFE_RELEASE( pMeshContainer->pBoneCombinationBuf );		
	SAFE_RELEASE( pMeshContainer->MeshData.pMesh );
	SAFE_RELEASE( pMeshContainer->MeshData.pPatchMesh );
	SAFE_RELEASE( pMeshContainer->MeshData.pPMesh );
	SAFE_RELEASE( pMeshContainer->pSkinInfo );	
	SAFE_RELEASE( pMeshContainer->pOrigMesh );

	SAFE_DELETE( pMeshContainer );
	return S_OK;
}

bool CMesh::GenerateSkinnedMesh(LPD3DXFRAME pCurFrame)
{
	if(pCurFrame == NULL)
		return true;

	// init skinned mesh
	MESHCONTAINER *pCurMeshContainer = (MESHCONTAINER*)pCurFrame->pMeshContainer;
	while(pCurMeshContainer != NULL)
	{
		// check if skinned mesh
		if(pCurMeshContainer->pSkinInfo != NULL)
		{
			if (m_bEnableVertexBlending)
			{
				// release since we had a reference a while back
				pCurMeshContainer->MeshData.pMesh->Release();

				if(FAILED(pCurMeshContainer->pSkinInfo->ConvertToBlendedMesh(
					pCurMeshContainer->pOrigMesh,
					D3DXMESH_MANAGED|D3DXMESHOPT_VERTEXCACHE, 
					pCurMeshContainer->pAdjacency, 
					NULL, NULL, NULL, 
					&pCurMeshContainer->dwNumInfl,
					&pCurMeshContainer->dwNumAttributeGroups, 
					&pCurMeshContainer->pBoneCombinationBuf, 
					&pCurMeshContainer->MeshData.pMesh
					)))
					return false;			
			}
			else
			{
				// release since we had a reference a while back
				pCurMeshContainer->MeshData.pMesh->Release();
				 
				pCurMeshContainer->pOrigMesh->CloneMeshFVF(
					D3DXMESH_MANAGED, pCurMeshContainer->pOrigMesh->GetFVF(),
					m_pDevice, &pCurMeshContainer->MeshData.pMesh);

				pCurMeshContainer->MeshData.pMesh->GetAttributeTable(NULL, &pCurMeshContainer->dwNumAttributeGroups);

				delete [] pCurMeshContainer->pAttributeTable;
				pCurMeshContainer->pAttributeTable  = new D3DXATTRIBUTERANGE[pCurMeshContainer->dwNumAttributeGroups];

				pCurMeshContainer->MeshData.pMesh->GetAttributeTable(pCurMeshContainer->pAttributeTable, NULL);

				pCurMeshContainer->dwNumBones = pCurMeshContainer->pSkinInfo->GetNumBones();

				// Allocate space for blend matrices			
				pCurMeshContainer->pBoneMatrices  = new D3DXMATRIX[pCurMeshContainer->dwNumBones];		
			}
		}

		// load textures, it's here so i could construct the full path for the texture
		for (DWORD iMaterial = 0; iMaterial < pCurMeshContainer->NumMaterials; iMaterial++)
		{			
			if (pCurMeshContainer->pMaterials[iMaterial].pTextureFilename != NULL)
			{
				// create path for texture
				char *pTexturePath = NULL;
				// search last occurance of '\'
				char *pCh = strrchr(m_pFilename, '\\');
				if(pCh != NULL) // attach				{
				{
					// get offset from last occurance of '\'
					int iOffset = pCh - m_pFilename + 1;
					pTexturePath = new char[iOffset + strlen(pCurMeshContainer->pMaterials[iMaterial].pTextureFilename) + 1];
					memcpy(pTexturePath, m_pFilename, iOffset);
					pTexturePath[iOffset] = 0; // add nul terminator
					strcat(pTexturePath, pCurMeshContainer->pMaterials[iMaterial].pTextureFilename);
				}
				// then the texture filename must be on the same directory of the current app
				else
				{
					pTexturePath = new char[strlen(pCurMeshContainer->pMaterials[iMaterial].pTextureFilename) + 1];
					strcpy(pTexturePath, pCurMeshContainer->pMaterials[iMaterial].pTextureFilename);
				}

				if( FAILED( D3DXCreateTextureFromFile( m_pDevice, pTexturePath,
					&pCurMeshContainer->ppTextures[iMaterial] ) ) )
					pCurMeshContainer->ppTextures[iMaterial] = NULL;

				// now we delete
				delete [] pTexturePath;
				pTexturePath = NULL;
				// we allocated awhile ago while loading the mesh
				delete [] pCurMeshContainer->pMaterials[iMaterial].pTextureFilename;
					pCurMeshContainer->pMaterials[iMaterial].pTextureFilename = NULL;
			}
		}
		m_dwNumMeshes++;
		pCurMeshContainer = (MESHCONTAINER*)pCurMeshContainer->pNextMeshContainer;
	}
    
	if(pCurFrame->pFrameFirstChild != NULL)
		if(!GenerateSkinnedMesh(pCurFrame->pFrameFirstChild))
			return false;

	if(pCurFrame->pFrameSibling != NULL)
		if(!GenerateSkinnedMesh(pCurFrame->pFrameSibling))
			return false;

	return true;
}

bool CMesh::MapFramesToBones(LPD3DXFRAME pCurFrame)
{
	UINT iBone, cBones;
	FRAME *pFrame = (FRAME*)pCurFrame;

	if(pCurFrame->pMeshContainer != NULL)
	{
		MESHCONTAINER *pMeshContainer = (MESHCONTAINER*)pCurFrame->pMeshContainer;		

		// if there is a skinmesh , then setup the bone matrices
		if (pMeshContainer->pSkinInfo != NULL)
		{
			cBones = pMeshContainer->pSkinInfo->GetNumBones();
			pMeshContainer->ppBoneMatrixPtrs = new D3DXMATRIX*[cBones];

			for(iBone = 0; iBone < cBones; iBone++)
			{
				// get a pointer to the frame
				pFrame = (FRAME*)D3DXFrameFind(m_pFrameRoot, pMeshContainer->pSkinInfo->GetBoneName(iBone));
				// get a pointer to the frame's combined matrix
				pMeshContainer->ppBoneMatrixPtrs[iBone] = &pFrame->matCombined;
			}
		}		
	}    

	if (pCurFrame->pFrameFirstChild != NULL)
		MapFramesToBones(pCurFrame->pFrameFirstChild);

	if (pCurFrame->pFrameSibling != NULL)   
		MapFramesToBones(pCurFrame->pFrameSibling);

	return true;
}

CMesh::CMesh(void) : 
m_vBoxMin(0.0f, 0.0f, 0.0f),
m_vBoxMax(0.0f, 0.0f, 0.0f),
m_vSphereCenter(0.0f, 0.0f, 0.0f)
{
	m_pFrameRoot		= NULL;
	m_pAnimController	= NULL;
	m_pStaticMesh		= NULL;

	m_dwNumMeshes		= 0;	
	m_fSphereRadius		= 0;

	m_pFilename			= NULL;
	m_pBoundingSphere	= NULL;
	m_pBoundingBox		= NULL;
}

CMesh::~CMesh(void)
{
	CAllocateHierarchy Alloc;
	D3DXFrameDestroy(m_pFrameRoot, &Alloc);	

	if(m_pAnimController != NULL)
	{
		m_pAnimController->Release();
		m_pAnimController = NULL;
	}
	if(m_pBoundingSphere != NULL)
	{
		m_pBoundingSphere->Release();
		m_pBoundingSphere = NULL;
	}
	if(m_pBoundingBox != NULL)
	{
		m_pBoundingBox->Release();
		m_pBoundingBox = NULL;
	}
	if(m_pStaticMesh != NULL)
	{
		m_pStaticMesh->Release();
		m_pStaticMesh = NULL;
	}
	if(m_pFilename != NULL)
	{
		delete [] m_pFilename;
		m_pFilename = NULL;
	}
}

#include 
using namespace std;

bool CMesh::Load(LPDIRECT3DDEVICE9 pDevice, char *pFilename, bool bVertexBlending)
{
	m_pDevice = pDevice;
	m_bEnableVertexBlending = bVertexBlending;
	char cError[128];

	// store filename
	m_pFilename = new char[strlen(pFilename) + 1];
	strcpy(m_pFilename, pFilename);

	CAllocateHierarchy Alloc;

	if(SUCCEEDED(D3DXLoadMeshHierarchyFromX(pFilename, 
		D3DXMESH_MANAGED, m_pDevice, &Alloc, NULL, &m_pFrameRoot, &m_pAnimController)))
	{
		// load it also as a static mesh
		D3DXLoadMeshFromX(pFilename, D3DXMESH_MANAGED, m_pDevice,
		NULL, NULL, NULL, NULL, &m_pStaticMesh);
	}
	else
	{
		sprintf(cError, "Failed to load mesh: %s", pFilename);
		throw(cError);
	}	

	// create skinned mesh
	if(!GenerateSkinnedMesh(m_pFrameRoot))
		return false;

	MapFramesToBones(m_pFrameRoot);	

//	if(FAILED(D3DXFrameCalculateBoundingSphere(m_pFrameRoot, 
//		&m_vSphereCenter, &m_fSphereRadius)))
//		return false;	

	if(!InitBounds())
		return false;

	return true;
}

bool CMesh::InitBounds()
{	
	D3DXVECTOR3 vBoxMin, vBoxMax;
	float fRadius;
	LPD3DXFRAME pCurFrame = m_pFrameRoot;
	LPD3DXMESHCONTAINER pCurMesh;
	stack st;
	st.push(pCurFrame);
	while(!st.empty())
	{
		pCurFrame = st.top();
		st.pop();
		if(pCurFrame != NULL)
		{
			pCurMesh = pCurFrame->pMeshContainer;
			while(pCurMesh != NULL)
			{
				if(pCurMesh->MeshData.pMesh != NULL)
				{
					BYTE *pVertices;
					pCurMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);				
					D3DXComputeBoundingBox( (D3DXVECTOR3*)pVertices, pCurMesh->MeshData.pMesh->GetNumVertices(), 
						D3DXGetFVFVertexSize(pCurMesh->MeshData.pMesh->GetFVF()), &vBoxMin, &vBoxMax );
					// m_vSphere center is dummy, dx function won't work if not filled
					D3DXComputeBoundingSphere((D3DXVECTOR3*)pVertices, pCurMesh->MeshData.pMesh->GetNumVertices(), 
						D3DXGetFVFVertexSize(pCurMesh->MeshData.pMesh->GetFVF()), &m_vSphereCenter, &fRadius);
					pCurMesh->MeshData.pMesh->UnlockVertexBuffer();

					m_vBoxMin.x = min(m_vBoxMin.x, vBoxMin.x);
					m_vBoxMin.y = min(m_vBoxMin.y, vBoxMin.y);
					m_vBoxMin.z = min(m_vBoxMin.z, vBoxMin.z);
					m_vBoxMax.x = max(m_vBoxMax.x, vBoxMax.x);
					m_vBoxMax.y = max(m_vBoxMax.y, vBoxMax.y);
					m_vBoxMax.z = max(m_vBoxMax.z, vBoxMax.z);
					m_fSphereRadius = max(m_fSphereRadius, fRadius);
				}
				pCurMesh = pCurMesh->pNextMeshContainer;
			}
			st.push(pCurFrame->pFrameFirstChild);
			st.push(pCurFrame->pFrameSibling);			
		}
	}
	m_vSphereCenter = (m_vBoxMax + m_vBoxMin) / 2.0f;		

	BYTE* pVertices;
	m_pStaticMesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)&pVertices);
	D3DXComputeBoundingBox( (D3DXVECTOR3*)pVertices, m_pStaticMesh->GetNumVertices(), 
		D3DXGetFVFVertexSize(m_pStaticMesh->GetFVF()), &m_vMind, &m_vMaxd );
	D3DXComputeBoundingSphere((D3DXVECTOR3*)pVertices, m_pStaticMesh->GetNumVertices(), 
		D3DXGetFVFVertexSize(m_pStaticMesh->GetFVF()), &m_vCenterd, &m_fRadiusd);
	m_pStaticMesh->UnlockVertexBuffer();			

	D3DXCreateBox(m_pDevice, fabs(m_vBoxMax.x - m_vBoxMin.x), fabs(m_vBoxMax.y - m_vBoxMin.y), 
		fabs(m_vBoxMax.z - m_vBoxMin.z), &m_pBoundingBox, NULL);
	D3DXCreateSphere(m_pDevice, m_fSphereRadius, 12, 12, &m_pBoundingSphere, NULL);

	D3DXComputeNormals(m_pBoundingBox, NULL);
	D3DXComputeNormals(m_pBoundingSphere, NULL);

	return true;
}


void CMesh::SaveHierarchyToFile()
{
/*	m_DebugString += ":::::Frame Hierarchy:::::\n\n";	
	PrintFrame(m_pFrameRoot);

	// print meshes
	m_DebugString += "\n\n:::::Mesh List:::::\n\n";	

	LPD3DXFRAME pCurFrame = m_pFrameRoot;
	D3DXMESHCONTAINER *pCurMesh;// = m_pFrameRoot->pMeshContainer;

	stack st;
	st.push(pCurFrame);
	while(!st.empty())
	{
		pCurFrame = st.top();
		st.pop();
		if(pCurFrame != NULL)
		{
			pCurMesh = pCurFrame->pMeshContainer;
			while(pCurMesh != NULL)
			{
				m_DebugString += pCurMesh->Name;
				m_DebugString += '\n';		
				// next mesh in list
				pCurMesh = pCurMesh->pNextMeshContainer;
			}
			st.push(pCurFrame->pFrameFirstChild);			
			st.push(pCurFrame->pFrameSibling);			
		}
	}

	// print animationasets	
	m_DebugString += "\n\n:::::Animation List:::::\n\n";	
	if(m_pAnimController != NULL)
	{
		LPD3DXANIMATIONSET pAnimSet = NULL;
		LPD3DXKEYFRAMEINTERPOLATOR pInterpolator = NULL;
		for(DWORD i = 0; i < m_pAnimController->GetNumAnimationSets(); i++)
		{
			m_pAnimController->GetAnimationSet(i, &pAnimSet);

			if(pAnimSet->GetName() == NULL)
				m_DebugString += "Unnamed";
			else
				m_DebugString += pAnimSet->GetName();

			m_DebugString += '\n';
			for(DWORD j = 0; j < pAnimSet->GetNumInterpolators(); j++)
			{
				pAnimSet->GetInterpolatorByIndex(j, (LPD3DXINTERPOLATOR*)&pInterpolator);	
				m_DebugString += "   ";
				m_DebugString += pInterpolator->GetName(),
				m_DebugString += '\n';
				pInterpolator->Release();
				pInterpolator = NULL;
			}				

			pAnimSet->Release();
			pAnimSet = NULL;
			m_DebugString += '\n';
		}
	}

	char cBuffer[128];
	m_DebugString += "\n\n:::::Other Stuff:::::\n\n";	
	sprintf(cBuffer, "Bounding Box\nMin\n x:%.3f\n y:%.3f\n z:%.3f\nMax\n x:%.3f\n y:%.3f\n z:%.3f\n", \
		m_vBoxMin.x, m_vBoxMin.y, m_vBoxMin.z, m_vBoxMax.x, m_vBoxMax.y, m_vBoxMax.z);	
	m_DebugString += cBuffer;
	sprintf(cBuffer, "Bounding Sphere Center\n x:%.3f\n y:%.3f\n z:%.3f\n radius:%.3f\n", \
		m_vSphereCenter.x, m_vSphereCenter.y, m_vSphereCenter.z, m_fSphereRadius);
	m_DebugString += cBuffer;

	m_DebugString += "\n\n:::::With D:::::\n\n";	
	sprintf(cBuffer, "Bounding Box\nMin\n x:%.3f\n y:%.3f\n z:%.3f\nMax\n x:%.3f\n y:%.3f\n z:%.3f\n", \
		m_vMind.x, m_vMind.y, m_vMind.z, m_vMaxd.x, m_vMaxd.y, m_vMaxd.z);	
	m_DebugString += cBuffer;
	sprintf(cBuffer, "Bounding Sphere Center\n x:%.3f\n y:%.3f\n z:%.3f\n radius:%.3f\n", \
		m_vCenterd.x, m_vCenterd.y, m_vCenterd.z, m_fRadiusd);
	m_DebugString += cBuffer;

	char *p = "_log.txt";
	char *pOutputFilename = new char[strlen(p) + strlen(m_pFilename) + 1];
	strcpy(pOutputFilename, m_pFilename);	
	strcat(pOutputFilename, p);	

	// now write to file
	ofstream fout(pOutputFilename);
	fout << m_DebugString;	
	fout << endl << "Total numbers of frames: " << D3DXFrameNumNamedMatrices(m_pFrameRoot);
	fout << endl << "Total number of mesh: " << m_dwNumMeshes;
	if(m_pAnimController != NULL)
		fout << endl << "Total number of AnimationSets: " << m_pAnimController->GetNumAnimationSets();	
	else
		fout << endl << "Total number of AnimationSets: 0" << endl;
	fout.close();

	delete [] pOutputFilename;
	pOutputFilename = NULL;
	p = NULL;*/
}

void CMesh::PrintFrame(D3DXFRAME *pCurFrame)
{
/*	static int space = 0;

	if(pCurFrame == NULL)
		return;

	for(int i = 0; i < space; i++)
		m_DebugString += ' ';		

	m_DebugString += pCurFrame->Name;
	m_DebugString += '\n';	

	space += 3;
	if(pCurFrame->pFrameFirstChild != NULL)
		PrintFrame(pCurFrame->pFrameFirstChild);	

	space -=3;	
	if(pCurFrame->pFrameSibling != NULL)
		PrintFrame(pCurFrame->pFrameSibling);*/
}

The mesh is just an ordinary .x file with skinweight chunks of data. I can't post it here, because it is 4MB in size. Thanks Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

Does the error occur in the code you posted? If so, which line is it? From the error, one would guess that you're trying to read from a pointer that's NULL.

 

Suggestion: set breakpoints in your code as you load the file to determine (e.g.) in which section of code the error occurs. As you narrow it down, start stepping through each line until the error occurs.

 

Without more definitive information, it's difficult to help you further.

Share this post


Link to post
Share on other sites

Something, either in your code or someone else's, is throwing an exception of type "char". You can find the origin of that exception in Visual Studio by going to the Debug menu, choosing Exceptions, and checking the box next to Win32 Exceptions as well as C++ Exceptions; just run under the debugger with those ticked and it should drop you right on the offending line.

Share this post


Link to post
Share on other sites

This topic is 1279 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this