From f96ea12fe77695bd6f275b59e28c200c2359b004 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:32:48 -0700 Subject: [PATCH] fix(m2): reject NaN inputs at M2Renderer::createInstance Even with all the upstream guards I've been adding, internal callers or addon-style scripted spawns could pass NaN. Reject at the API boundary so we never hash-key with NaN coords (std::round of NaN is implementation-defined) or push a NaN instance into the model- matrix uniform buffer (GPU crash / origin render). --- src/rendering/m2_renderer_render.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/rendering/m2_renderer_render.cpp b/src/rendering/m2_renderer_render.cpp index 8c29df28..00ee7c35 100644 --- a/src/rendering/m2_renderer_render.cpp +++ b/src/rendering/m2_renderer_render.cpp @@ -36,6 +36,15 @@ namespace rendering { uint32_t M2Renderer::createInstance(uint32_t modelId, const glm::vec3& position, const glm::vec3& rotation, float scale) { + // Reject NaN inputs at the boundary — std::round of NaN is implementation- + // defined and a NaN instance position propagates into the GPU model matrix, + // either tripping Vulkan validation or rendering at the world origin. + if (!std::isfinite(position.x) || !std::isfinite(position.y) || + !std::isfinite(position.z) || !std::isfinite(rotation.x) || + !std::isfinite(rotation.y) || !std::isfinite(rotation.z) || + !std::isfinite(scale) || scale <= 0.0f) { + return 0; + } auto modelIt = models.find(modelId); if (modelIt == models.end()) { LOG_WARNING("Cannot create instance: model ", modelId, " not loaded");