diff --git a/src/pipeline/wowee_model.cpp b/src/pipeline/wowee_model.cpp index a609a946..f365809f 100644 --- a/src/pipeline/wowee_model.cpp +++ b/src/pipeline/wowee_model.cpp @@ -395,9 +395,14 @@ bool WoweeModelLoader::save(const WoweeModel& model, const std::string& basePath if (totalTex > 0 && b.textureIndex >= totalTex) continue; validBatches.push_back(b); } - uint32_t batchCount = static_cast(validBatches.size()); + // Cap batches at the load limit (4096). validBatches has already + // dropped invalid entries; this trims the head if the model has + // more than the loader will accept. + uint32_t batchCount = static_cast( + std::min(validBatches.size(), 4096)); f.write(reinterpret_cast(&batchCount), 4); - for (const auto& b : validBatches) { + for (uint32_t bi = 0; bi < batchCount; bi++) { + const auto& b = validBatches[bi]; f.write(reinterpret_cast(&b.indexStart), 4); f.write(reinterpret_cast(&b.indexCount), 4); f.write(reinterpret_cast(&b.textureIndex), 4);