mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 11:48:52 +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];
|
outVertex = blendshape.vertices[lookupIndex];
|
||||||
} else {
|
} else {
|
||||||
// Index isn't in the blendshape, so return vertex from mesh
|
// 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];
|
return &normalsOut[normalIndex];
|
||||||
},
|
},
|
||||||
[&mesh](int vertexIndex, glm::vec3& outVertex) /* VertexSetter */ {
|
[&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
|
// 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)>;
|
using NormalAccessor = std::function<glm::vec3*(int index)>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue