mirror of
https://github.com/lubosz/overte.git
synced 2025-04-07 04:42:49 +02:00
Fix crash due to invalid indices in baker::calculateNormals
This commit is contained in:
parent
9261df5c24
commit
0b3f2b1765
3 changed files with 13 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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)>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue