RemoveRedundantMaterials: avoid crash when all materials are redundant
parent
ac29847d56
commit
cbe3bbd723
|
@ -3,7 +3,7 @@
|
||||||
Open Asset Import Library (assimp)
|
Open Asset Import Library (assimp)
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
Copyright (c) 2006-2022, assimp team
|
Copyright (c) 2006-2024, assimp team
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
@ -153,11 +153,12 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
|
||||||
}
|
}
|
||||||
// If the new material count differs from the original,
|
// If the new material count differs from the original,
|
||||||
// we need to rebuild the material list and remap mesh material indexes.
|
// we need to rebuild the material list and remap mesh material indexes.
|
||||||
if(iNewNum < 1)
|
|
||||||
throw DeadlyImportError("No materials remaining");
|
|
||||||
if (iNewNum != pScene->mNumMaterials) {
|
if (iNewNum != pScene->mNumMaterials) {
|
||||||
ai_assert(iNewNum > 0);
|
aiMaterial** ppcMaterials;
|
||||||
aiMaterial** ppcMaterials = new aiMaterial*[iNewNum];
|
if (iNewNum == 0) {
|
||||||
|
ppcMaterials = nullptr;
|
||||||
|
} else {
|
||||||
|
ppcMaterials = new aiMaterial*[iNewNum];
|
||||||
::memset(ppcMaterials,0,sizeof(void*)*iNewNum);
|
::memset(ppcMaterials,0,sizeof(void*)*iNewNum);
|
||||||
for (unsigned int p = 0; p < pScene->mNumMaterials;++p)
|
for (unsigned int p = 0; p < pScene->mNumMaterials;++p)
|
||||||
{
|
{
|
||||||
|
@ -184,6 +185,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
|
||||||
ai_assert(nullptr != mesh);
|
ai_assert(nullptr != mesh);
|
||||||
mesh->mMaterialIndex = aiMappingTable[mesh->mMaterialIndex];
|
mesh->mMaterialIndex = aiMappingTable[mesh->mMaterialIndex];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// delete the old material list
|
// delete the old material list
|
||||||
delete[] pScene->mMaterials;
|
delete[] pScene->mMaterials;
|
||||||
pScene->mMaterials = ppcMaterials;
|
pScene->mMaterials = ppcMaterials;
|
||||||
|
|
Loading…
Reference in New Issue