mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 01:23:52 +00:00
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:
parent
94469592f2
commit
cdc9bb94ee
1 changed files with 5 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue