From de983c2728505586521d503bce325f64317292ff Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 05:10:04 -0700 Subject: [PATCH] fix(whm): replace NaN/inf chunk base + per-vertex heights with 0.0 on load A WHM with non-finite height values would produce non-finite vertex positions in the terrain mesh, breaking collision queries, pathing, and the GPU's matrix math. Both the chunk base (one float per chunk) and the 145 per-vertex heights are now individually validated. --- src/pipeline/wowee_terrain_loader.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pipeline/wowee_terrain_loader.cpp b/src/pipeline/wowee_terrain_loader.cpp index ae89a45c..989053bc 100644 --- a/src/pipeline/wowee_terrain_loader.cpp +++ b/src/pipeline/wowee_terrain_loader.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace wowee { namespace pipeline { @@ -46,9 +47,16 @@ bool WoweeTerrainLoader::loadHeightmap(const std::string& whmPath, ADTTerrain& t float base; f.read(reinterpret_cast(&base), 4); + // Reject NaN/inf chunk base height — would break collision/pathing + // and produce non-finite vertex positions in the terrain mesh. + if (!std::isfinite(base)) base = 0.0f; chunk.position[2] = base; f.read(reinterpret_cast(chunk.heightMap.heights.data()), 145 * 4); + // Same guard applied per-vertex. + for (auto& h : chunk.heightMap.heights) { + if (!std::isfinite(h)) h = 0.0f; + } // Read alpha map data (may not be present in older WHM files) uint32_t alphaSize = 0;