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.
This commit is contained in:
Kelsi 2026-05-06 05:10:04 -07:00
parent 2b02ca6b58
commit de983c2728

View file

@ -4,6 +4,7 @@
#include <fstream>
#include <filesystem>
#include <cstring>
#include <cmath>
namespace wowee {
namespace pipeline {
@ -46,9 +47,16 @@ bool WoweeTerrainLoader::loadHeightmap(const std::string& whmPath, ADTTerrain& t
float base;
f.read(reinterpret_cast<char*>(&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<char*>(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;