From 507dfd70d1c982143e325fe4e4ae2333f9fc4c60 Mon Sep 17 00:00:00 2001 From: Human Gamer <39096122+HumanGamer@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:00:22 -0500 Subject: [PATCH] Fixed trapdoors causing crash --- common/src/IO/AssimpParser.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/src/IO/AssimpParser.cpp b/common/src/IO/AssimpParser.cpp index 642519e671..7feb65ac17 100644 --- a/common/src/IO/AssimpParser.cpp +++ b/common/src/IO/AssimpParser.cpp @@ -561,6 +561,8 @@ std::vector computeMeshVertices( return vertices; } + bool bonesFailed = false; + // the weights for each vertex are stored in the bones, not in // the vertices. this loop lets us collect the bone weightings // per vertex so we can process them. @@ -575,6 +577,11 @@ std::vector computeMeshVertices( { for (unsigned int j = 0; j < bone.mNumWeights; ++j) { + if (bone.mWeights[j].mVertexId >= mesh.mNumVertices) + { + bonesFailed = true; + break; + } weightsPerVertex[bone.mWeights[j].mVertexId].push_back( {*index, bone.mWeights[j].mWeight, bone}); } @@ -595,7 +602,7 @@ std::vector computeMeshVertices( auto meshVertices = mesh.mVertices[i]; // Bone indices and weights - if (mesh.HasBones() && !boneTransforms.empty() && !weightsPerVertex[i].empty()) + if (!bonesFailed && mesh.HasBones() && !boneTransforms.empty() && !weightsPerVertex[i].empty()) { const auto vertWeights = weightsPerVertex[i]; auto vertPos = aiVector3D{};