mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-06 09:03:52 +00:00
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).
This commit is contained in:
parent
f6187e7f9a
commit
804c7d3d60
1 changed files with 6 additions and 2 deletions
|
|
@ -438,8 +438,12 @@ M2Model WoweeModelLoader::toM2(const WoweeModel& wom) {
|
|||
batch.indexCount = wb.indexCount;
|
||||
batch.vertexCount = static_cast<uint32_t>(m.vertices.size());
|
||||
batch.textureCount = 1;
|
||||
batch.textureIndex = static_cast<uint16_t>(
|
||||
std::min<uint32_t>(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<uint16_t>(std::min<uint32_t>(wb.textureIndex, m.textureLookup.size() - 1));
|
||||
batch.textureIndex = safeTexIdx;
|
||||
batch.materialIndex = static_cast<uint16_t>(m.materials.size());
|
||||
m.batches.push_back(batch);
|
||||
M2Material mat;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue