From dbb3be86f2e024572f7f6b8b966c6d86871a0bce Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 07:28:31 -0700 Subject: [PATCH] fix(wom): clamp out-of-range indices at save time Symmetric with the load-side index clamp. A WoM whose indices reference past the vertex buffer would crash the GPU vertex shader; the save side now clamps to 0 (degenerate triangle) so the file matches what the load guard would produce. --- src/pipeline/wowee_model.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pipeline/wowee_model.cpp b/src/pipeline/wowee_model.cpp index 2805de50..2fec112e 100644 --- a/src/pipeline/wowee_model.cpp +++ b/src/pipeline/wowee_model.cpp @@ -298,7 +298,15 @@ bool WoweeModelLoader::save(const WoweeModel& model, const std::string& basePath } } - f.write(reinterpret_cast(model.indices.data()), indexCount * 4); + // Clamp out-of-range indices on save too — symmetric with the load + // guard. Avoids writing index values that the renderer would refuse + // and that the load-time guard would have to clean up later. + { + const uint32_t vMax = vertCount > 0 ? vertCount - 1 : 0; + std::vector sanIdx = model.indices; + for (auto& idx : sanIdx) if (idx > vMax) idx = 0; + f.write(reinterpret_cast(sanIdx.data()), indexCount * 4); + } for (const auto& path : model.texturePaths) writeStr(path);