From 0547ab882a409501c0138986e4162879659a93b2 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 09:13:34 -0700 Subject: [PATCH] fix(wob): cap per-portal vertex count on save to match load limit Same per-section cap pattern. Real portals carry 4-12 verts; the load enforces 4096 max. Save previously wrote raw size() so a huge portal would write a header the loader rejects. --- src/pipeline/wowee_building.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pipeline/wowee_building.cpp b/src/pipeline/wowee_building.cpp index 110f6e73..82f7873c 100644 --- a/src/pipeline/wowee_building.cpp +++ b/src/pipeline/wowee_building.cpp @@ -308,12 +308,16 @@ bool WoweeBuildingLoader::save(const WoweeBuilding& bld, const std::string& base const auto& portal = bld.portals[pi]; f.write(reinterpret_cast(&portal.groupA), 4); f.write(reinterpret_cast(&portal.groupB), 4); - uint32_t pvCount = static_cast(portal.vertices.size()); + // Cap per-portal vertex count at the load limit (4096). Real + // portals are 4-12 verts; >4096 would be rejected on round-trip. + uint32_t pvCount = static_cast( + std::min(portal.vertices.size(), 4096)); f.write(reinterpret_cast(&pvCount), 4); // Sanitize vertices on the way out — NaN portal vertices break // the WMO portal-frustum cull and fail-back to drawing the entire // building, defeating the indoor optimization. - std::vector sanPortal = portal.vertices; + std::vector sanPortal(portal.vertices.begin(), + portal.vertices.begin() + pvCount); for (auto& v : sanPortal) { if (!std::isfinite(v.x)) v.x = 0.0f; if (!std::isfinite(v.y)) v.y = 0.0f;