From b7e3266c7a0d9ec9adb515c79dd95550dab63727 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:36:11 -0700 Subject: [PATCH] fix(m2): NaN guards on createInstanceWithMatrix boundary Mirrors the createInstance guard. position drives the dedup hash key (std::round of NaN is implementation-defined) and the matrix flows into the GPU UBO. --- src/rendering/m2_renderer_render.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/rendering/m2_renderer_render.cpp b/src/rendering/m2_renderer_render.cpp index 00ee7c35..bee42b03 100644 --- a/src/rendering/m2_renderer_render.cpp +++ b/src/rendering/m2_renderer_render.cpp @@ -163,6 +163,16 @@ uint32_t M2Renderer::createInstance(uint32_t modelId, const glm::vec3& position, uint32_t M2Renderer::createInstanceWithMatrix(uint32_t modelId, const glm::mat4& modelMatrix, const glm::vec3& position) { + // Reject NaN inputs at the boundary. position feeds the dedup hash + // (std::round of NaN is implementation-defined); the matrix goes + // straight to the GPU UBO and would crash validation. + if (!std::isfinite(position.x) || !std::isfinite(position.y) || + !std::isfinite(position.z)) { + return 0; + } + for (int c = 0; c < 4; c++) + for (int r = 0; r < 4; r++) + if (!std::isfinite(modelMatrix[c][r])) return 0; if (models.find(modelId) == models.end()) { LOG_WARNING("Cannot create instance: model ", modelId, " not loaded"); return 0;