From 804c7d3d60e4d90d29df746896d5d4fc3b6944ec Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 02:00:52 -0700 Subject: [PATCH] fix(wom): toM2 handles WOM3 batches with empty textureLookup safely Previously `m.textureLookup.size() - 1` would underflow to UINT_MAX when texturePaths was empty, then std::min would clamp the bad value into the batch. Renderer would either crash or sample bogus memory. Now treats an empty lookup as textureIndex=0 (white-texture fallback path). --- src/pipeline/wowee_model.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pipeline/wowee_model.cpp b/src/pipeline/wowee_model.cpp index 12d9d343..962d678c 100644 --- a/src/pipeline/wowee_model.cpp +++ b/src/pipeline/wowee_model.cpp @@ -438,8 +438,12 @@ M2Model WoweeModelLoader::toM2(const WoweeModel& wom) { batch.indexCount = wb.indexCount; batch.vertexCount = static_cast(m.vertices.size()); batch.textureCount = 1; - batch.textureIndex = static_cast( - std::min(wb.textureIndex, m.textureLookup.size() - 1)); + // textureLookup may be empty when the WOM has no textures at all; + // in that case the renderer falls back to its white default. + uint16_t safeTexIdx = m.textureLookup.empty() + ? 0 + : static_cast(std::min(wb.textureIndex, m.textureLookup.size() - 1)); + batch.textureIndex = safeTexIdx; batch.materialIndex = static_cast(m.materials.size()); m.batches.push_back(batch); M2Material mat;