fix(m2): skip NaN vertices when computing tight model bounds

glm::min/max on NaN is implementation-defined, so a single bad
vertex would propagate NaN into the camera-occlusion and culling
AABB used by the runtime. WOM/M2 loaders already scrub but defense
in depth catches anything they miss. Falls back to a unit box if
every vertex is bad.
This commit is contained in:
Kelsi 2026-05-06 08:51:31 -07:00
parent 61fb486b9e
commit cfd257aa78

View file

@ -1170,9 +1170,20 @@ bool M2Renderer::loadModel(const pipeline::M2Model& model, uint32_t modelId) {
tightMin = glm::vec3(std::numeric_limits<float>::max());
tightMax = glm::vec3(-std::numeric_limits<float>::max());
for (const auto& v : model.vertices) {
// Skip NaN-positioned vertices — would corrupt the bounds
// (glm::min on NaN is implementation-defined) and feed NaN
// into the camera-occlusion / culling AABB.
if (!std::isfinite(v.position.x) || !std::isfinite(v.position.y) ||
!std::isfinite(v.position.z)) continue;
tightMin = glm::min(tightMin, v.position);
tightMax = glm::max(tightMax, v.position);
}
// If all vertices were NaN (very unlikely after the loader scrub
// but defense in depth), fall back to a unit box around origin.
if (tightMin.x > tightMax.x) {
tightMin = glm::vec3(-1.0f);
tightMax = glm::vec3(1.0f);
}
}
// Classify model from name and geometry — pure function, no GPU dependencies.