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.
This commit is contained in:
Kelsi 2026-05-06 08:24:51 -07:00
parent 303eeb9107
commit 07f4043343

View file

@ -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) {