Kimkulling/fix bahavior of remove redundat mats issue 5438 (#5451)

* Fix crash in viewer

* Fix bevavior when material was not referenced
pull/5372/head^2
Kim Kulling 2024-02-01 21:27:04 +01:00 committed by GitHub
parent 3476c79801
commit 3990ec80a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 100 additions and 95 deletions

View File

@ -75,7 +75,10 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
ASSIMP_LOG_DEBUG("RemoveRedundantMatsProcess begin");
unsigned int redundantRemoved = 0, unreferencedRemoved = 0;
if (pScene->mNumMaterials) {
if (pScene->mNumMaterials == 0) {
return;
}
// Find out which materials are referenced by meshes
std::vector<bool> abReferenced(pScene->mNumMaterials,false);
for (unsigned int i = 0;i < pScene->mNumMeshes;++i)
@ -153,8 +156,10 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
}
// If the new material count differs from the original,
// we need to rebuild the material list and remap mesh material indexes.
if(iNewNum < 1)
throw DeadlyImportError("No materials remaining");
if (iNewNum < 1) {
//throw DeadlyImportError("No materials remaining");
return;
}
if (iNewNum != pScene->mNumMaterials) {
ai_assert(iNewNum > 0);
aiMaterial** ppcMaterials = new aiMaterial*[iNewNum];
@ -192,7 +197,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
// delete temporary storage
delete[] aiHashes;
delete[] aiMappingTable;
}
if (redundantRemoved == 0 && unreferencedRemoved == 0) {
ASSIMP_LOG_DEBUG("RemoveRedundantMatsProcess finished ");
} else {