Validate material indices, so we don't crash if a mesh references material 9999.

This commit is contained in:
Glenn Maynard
2005-02-10 02:40:56 +00:00
parent 16952cf29c
commit 36b99323fb
+10
View File
@@ -106,6 +106,16 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo
ASSERT( m_pGeometry == NULL );
m_pGeometry = MODELMAN->LoadMilkshapeAscii( sMeshesPath, this->MaterialsNeedNormals() );
/* Validate material indices. */
for( unsigned i = 0; i < m_pGeometry->m_Meshes.size(); ++i )
{
const msMesh *pMesh = &m_pGeometry->m_Meshes[i];
if( pMesh->nMaterialIndex >= (int) m_Materials.size() )
RageException::Throw( "Model \"%s\" mesh \"%s\" references material index %i, but there are only %i materials",
sMeshesPath.c_str(), pMesh->szName, pMesh->nMaterialIndex, m_Materials.size() );
}
if( LoadMilkshapeAsciiBones( DEFAULT_ANIMATION_NAME, sBonesPath ) )
PlayAnimation( DEFAULT_ANIMATION_NAME );