fix(editor): NPC + object position/rotation NaN guards on JSON load

Mirrors the recent scale guards. NaN/inf positions or rotations make
the M2 renderer's matrix math produce chaos-shaped instances or crash
during normal computation. Now both fields are reset to zero on load
when any component is non-finite.
This commit is contained in:
Kelsi 2026-05-06 05:04:25 -07:00
parent d525318e9c
commit 604d29d375
2 changed files with 14 additions and 0 deletions

View file

@ -301,11 +301,19 @@ bool ObjectPlacer::loadFromFile(const std::string& path) {
obj.position = glm::vec3(jo["pos"][0].get<float>(),
jo["pos"][1].get<float>(),
jo["pos"][2].get<float>());
if (!std::isfinite(obj.position.x) || !std::isfinite(obj.position.y) ||
!std::isfinite(obj.position.z)) {
obj.position = glm::vec3(0.0f);
}
}
if (jo.contains("rot") && jo["rot"].is_array() && jo["rot"].size() >= 3) {
obj.rotation = glm::vec3(jo["rot"][0].get<float>(),
jo["rot"][1].get<float>(),
jo["rot"][2].get<float>());
if (!std::isfinite(obj.rotation.x) || !std::isfinite(obj.rotation.y) ||
!std::isfinite(obj.rotation.z)) {
obj.rotation = glm::vec3(0.0f);
}
}
if (!obj.path.empty()) {