From cdc9bb94ee3576ec536b7da9c9369acf0a408c86 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:00:36 -0700 Subject: [PATCH] fix(npc): NaN guards in NpcSpawner::selectAt distance test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tools/editor/npc_spawner.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/editor/npc_spawner.cpp b/tools/editor/npc_spawner.cpp index eab5bd21..806c0a86 100644 --- a/tools/editor/npc_spawner.cpp +++ b/tools/editor/npc_spawner.cpp @@ -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(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) {