From 55f9616aa6c63e342ba7cab1bbe4ea86cb158ea7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:03:57 -0700 Subject: [PATCH] fix(camera): NaN guards on pivot orbit, setPosition, setYawPitch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three issues: - processMiddleMouseMotion: NaN pivot poisons camera position permanently; the next frame produces NaN view/proj matrices. - setPosition: no input validation — used by bookmark restore and fly-to-target which could be passed a NaN target. - setYawPitch: same; also clamp pitch to [-89, 89] to match the mouse-motion path so a saved bookmark with bad pitch doesn't roll the camera upside down. --- tools/editor/editor_camera.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/editor/editor_camera.cpp b/tools/editor/editor_camera.cpp index 3a17c108..066b2e26 100644 --- a/tools/editor/editor_camera.cpp +++ b/tools/editor/editor_camera.cpp @@ -1,6 +1,7 @@ #include "editor_camera.hpp" #include #include +#include namespace wowee { namespace editor { @@ -84,20 +85,29 @@ void EditorCamera::processMiddleMouseMotion(int dx, int dy, const glm::vec3& piv pitch_ = std::clamp(pitch_, -89.0f, 89.0f); camera_.setRotation(yaw_, pitch_); - // Orbit: maintain distance from pivot + // Orbit: maintain distance from pivot. Reject NaN pivot — would + // poison the camera position permanently and the next frame would + // produce NaN view/proj matrices. + if (!std::isfinite(pivotPoint.x) || !std::isfinite(pivotPoint.y) || + !std::isfinite(pivotPoint.z)) return; glm::vec3 toPivot = pivotPoint - camera_.getPosition(); float dist = glm::length(toPivot); + if (!std::isfinite(dist)) return; glm::vec3 newPos = pivotPoint - camera_.getForward() * dist; camera_.setPosition(newPos); } void EditorCamera::setPosition(const glm::vec3& pos) { + if (!std::isfinite(pos.x) || !std::isfinite(pos.y) || !std::isfinite(pos.z)) return; camera_.setPosition(pos); } void EditorCamera::setYawPitch(float yaw, float pitch) { + if (!std::isfinite(yaw) || !std::isfinite(pitch)) return; yaw_ = yaw; - pitch_ = pitch; + // Match the mouse-motion clamp so out-of-range pitch from a saved + // bookmark doesn't roll the camera upside down. + pitch_ = std::clamp(pitch, -89.0f, 89.0f); camera_.setRotation(yaw_, pitch_); }