Fix crash due to invalid indices in baker::calculateNormals

This commit is contained in:
sabrina-shanman 2019-04-30 14:48:48 -07:00
parent 9261df5c24
commit 0b3f2b1765
3 changed files with 13 additions and 2 deletions

View file

@ -61,7 +61,7 @@ void CalculateBlendshapeNormalsTask::run(const baker::BakeContextPointer& contex
outVertex = blendshape.vertices[lookupIndex];
} else {
// Index isn't in the blendshape, so return vertex from mesh
outVertex = mesh.vertices[lookupIndex];
outVertex = baker::safeGet(mesh.vertices, lookupIndex);
}
});
}

View file

@ -32,7 +32,7 @@ void CalculateMeshNormalsTask::run(const baker::BakeContextPointer& context, con
return &normalsOut[normalIndex];
},
[&mesh](int vertexIndex, glm::vec3& outVertex) /* VertexSetter */ {
outVertex = mesh.vertices[vertexIndex];
outVertex = baker::safeGet(mesh.vertices, vertexIndex);
}
);
}

View file

@ -25,6 +25,17 @@ namespace baker {
}
}
template<typename T>
const T& safeGet(const QVector<T>& data, int i) {
static T t;
if (i >= 0 && data.size() > i) {
return data[i];
} else {
return t;
}
}
// Returns a reference to the normal at the specified index, or nullptr if it cannot be accessed
using NormalAccessor = std::function<glm::vec3*(int index)>;