From 4a534c24e82837fe1a752042d3daa765f4abdd9a Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 09:04:18 -0700 Subject: [PATCH] fix(wob): cap material count at 256 on save (matches load limit) Save previously wrote raw materials.size() as the count, then iterated all materials. Load caps at 256, so a build with >256 materials would write fine but truncate on round-trip and the post-truncation block would be misread as the next group's data. Cap at save and only write the first 256. --- src/pipeline/wowee_building.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pipeline/wowee_building.cpp b/src/pipeline/wowee_building.cpp index 36d8c274..6cd00b29 100644 --- a/src/pipeline/wowee_building.cpp +++ b/src/pipeline/wowee_building.cpp @@ -279,10 +279,14 @@ bool WoweeBuildingLoader::save(const WoweeBuilding& bld, const std::string& base for (const auto& tp : grp.texturePaths) writeStr(tp); - // Write material data - uint32_t mc = static_cast(grp.materials.size()); + // Write material data — cap at 256 to match load-side limit so a + // pathological in-memory count can't write a file the loader will + // reject and produce a partially-zero build on round-trip. + uint32_t mc = static_cast( + std::min(grp.materials.size(), 256)); f.write(reinterpret_cast(&mc), 4); - for (const auto& mat : grp.materials) { + for (uint32_t mi = 0; mi < mc; mi++) { + const auto& mat = grp.materials[mi]; writeStr(mat.texturePath); f.write(reinterpret_cast(&mat.flags), 4); f.write(reinterpret_cast(&mat.shader), 4);