From 07f4043343ac5265e651e12a42dd42eb7efe66dc Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:24:51 -0700 Subject: [PATCH] fix(viewport): clear ghost preview on NaN/non-positive inputs Without this guard, NaN cursor position from a degenerate raycast would feed directly into the M2 renderer instance transform and either crash on GPU or silently render at the origin. --- tools/editor/editor_viewport.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/editor/editor_viewport.cpp b/tools/editor/editor_viewport.cpp index f84c628f..873d6dc5 100644 --- a/tools/editor/editor_viewport.cpp +++ b/tools/editor/editor_viewport.cpp @@ -658,6 +658,14 @@ void EditorViewport::update(float deltaTime) { void EditorViewport::setGhostPreview(const std::string& path, const glm::vec3& pos, const glm::vec3& rotDeg, float scale) { if (!m2Renderer_) return; + // Reject NaN inputs — would propagate into the M2 renderer transform + // and either crash on the GPU or silently render at the origin. + if (!std::isfinite(pos.x) || !std::isfinite(pos.y) || !std::isfinite(pos.z) || + !std::isfinite(rotDeg.x) || !std::isfinite(rotDeg.y) || !std::isfinite(rotDeg.z) || + !std::isfinite(scale) || scale <= 0.0f) { + clearGhostPreview(); + return; + } // Load model if path changed if (path != ghostModelPath_ || ghostModelId_ == 0) {