Skip to content

Commit

Permalink
Fixed trapdoors causing crash
Browse files Browse the repository at this point in the history
  • Loading branch information
HumanGamer committed Apr 5, 2024
1 parent 875c7ad commit 507dfd7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion common/src/IO/AssimpParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ std::vector<Assets::EntityModelVertex> 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.
Expand All @@ -575,6 +577,11 @@ std::vector<Assets::EntityModelVertex> 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});
}
Expand All @@ -595,7 +602,7 @@ std::vector<Assets::EntityModelVertex> 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{};
Expand Down

0 comments on commit 507dfd7

Please sign in to comment.