From 44777c7d58d5110afd8912ab3f8ef77407ec0dbc Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 08:11:43 -0700 Subject: [PATCH] fix(mesh): clamp NaN terrain heights to 0 in vertex generation WHM load already scrubs, but mid-edit terrain can briefly carry NaN before stitchEdges runs. A single NaN vertex propagates into normal computations and the chunk's frustum cull, crashing both. --- src/pipeline/terrain_mesh.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pipeline/terrain_mesh.cpp b/src/pipeline/terrain_mesh.cpp index efb4f9da..cf95335b 100644 --- a/src/pipeline/terrain_mesh.cpp +++ b/src/pipeline/terrain_mesh.cpp @@ -217,9 +217,14 @@ std::vector TerrainMeshGenerator::generateVertices(const MapChunk // Position in render space: // MCVT rows (offsetY) go west→east = renderX decreasing // MCVT columns (offsetX) go north→south = renderY decreasing + // NaN heights are clamped — WHM load scrubs but mid-edit terrain + // can briefly carry NaN before stitchEdges runs, and a single NaN + // vertex would propagate into normal computations and crash culling. + float h = heightMap.heights[index]; + if (!std::isfinite(h)) h = 0.0f; vertex.position[0] = chunkBaseX - (offsetY * unitSize); // renderX (row = west→east) vertex.position[1] = chunkBaseY - (offsetX * unitSize); // renderY (col = north→south) - vertex.position[2] = chunkBaseZ + heightMap.heights[index]; // renderZ + vertex.position[2] = chunkBaseZ + h; // renderZ // Normal if (index * 3 + 2 < static_cast(chunk.normals.size())) {