fix(npc): NaN guards in NpcSpawner::selectAt distance test

Same NaN-comparison short-circuit pattern: NaN worldPos or NaN
spawn position would short-circuit dist < bestDist (NaN < x is
false), so it never updates bestIdx — but if every entry had NaN
the bestIdx stays -1 (correct) only because the first comparison
also fails. Belt and braces: skip NaN entries explicitly.
This commit is contained in:
Kelsi 2026-05-06 08:00:36 -07:00
parent 94469592f2
commit cdc9bb94ee

View file

@ -31,10 +31,14 @@ void NpcSpawner::removeCreature(int index) {
int NpcSpawner::selectAt(const glm::vec3& worldPos, float maxDist) {
clearSelection();
if (!std::isfinite(worldPos.x) || !std::isfinite(worldPos.y) ||
!std::isfinite(worldPos.z) || !std::isfinite(maxDist)) return -1;
float bestDist = maxDist;
int bestIdx = -1;
for (int i = 0; i < static_cast<int>(spawns_.size()); i++) {
float dist = glm::length(spawns_[i].position - worldPos);
const auto& p = spawns_[i].position;
if (!std::isfinite(p.x) || !std::isfinite(p.y) || !std::isfinite(p.z)) continue;
float dist = glm::length(p - worldPos);
if (dist < bestDist) { bestDist = dist; bestIdx = i; }
}
if (bestIdx >= 0) {