From 439d1381f02d5d6d1bfc9f124798ae76717916c1 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 07:53:41 -0700 Subject: [PATCH] fix(editor): catch NaN-from-normalize when camera flies to a target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the camera looks straight up/down, projecting forward onto XY gives a zero vector — glm::normalize then returns NaN. The original length<0.001 fallback ran AFTER the divide-by-zero, and NaN length < 0.001 is false (NaN comparisons return false), so the fallback never fired. Length-check the source before normalizing. --- tools/editor/editor_app.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index b2b7059a..2d06fe83 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -1578,8 +1578,15 @@ void EditorApp::flyToSelected() { // both for tight spawn lists and for far-flung WMOs. glm::vec3 fwd = camera_.getCamera().getForward(); if (glm::length(fwd) < 0.001f) fwd = glm::vec3(1, 0, 0); - glm::vec3 back = -glm::normalize(glm::vec3(fwd.x, fwd.y, 0.0f)); - if (glm::length(back) < 0.001f) back = glm::vec3(-1, 0, 0); + // Project onto XY before normalizing — but if the camera is looking + // straight up/down, the projection is zero and glm::normalize returns + // NaN. NaN length < 0.001f is false (NaN comparisons return false), so + // the original fallback didn't catch the case. Length-check the source + // vector explicitly. + glm::vec3 fwdXY(fwd.x, fwd.y, 0.0f); + glm::vec3 back = (glm::length(fwdXY) < 0.001f) + ? glm::vec3(-1, 0, 0) + : -glm::normalize(fwdXY); glm::vec3 cam = target + back * 25.0f + glm::vec3(0, 0, 15); camera_.setPosition(cam);