mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-09 02:23:52 +00:00
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.
This commit is contained in:
parent
a0895fabdf
commit
dbb3be86f2
1 changed files with 9 additions and 1 deletions
|
|
@ -298,7 +298,15 @@ bool WoweeModelLoader::save(const WoweeModel& model, const std::string& basePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.write(reinterpret_cast<const char*>(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<uint32_t> sanIdx = model.indices;
|
||||||
|
for (auto& idx : sanIdx) if (idx > vMax) idx = 0;
|
||||||
|
f.write(reinterpret_cast<const char*>(sanIdx.data()), indexCount * 4);
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& path : model.texturePaths) writeStr(path);
|
for (const auto& path : model.texturePaths) writeStr(path);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue