From 4babaebf86d3c8ce99bac07ec9ed66caf0ec1a30 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 07:51:56 -0700 Subject: [PATCH] fix(stamp): scrub NaN samples at save time Symmetric with the load-side scrub. Without this, a stamp captured on terrain that had a NaN mid-edit would throw on serialize and abort the whole save. --- tools/editor/terrain_editor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/editor/terrain_editor.cpp b/tools/editor/terrain_editor.cpp index d1bc48ec..95abb3d3 100644 --- a/tools/editor/terrain_editor.cpp +++ b/tools/editor/terrain_editor.cpp @@ -1528,9 +1528,12 @@ bool TerrainEditor::saveStamp(const std::string& path) const { nlohmann::json j; j["format"] = "wowee-stamp-1.0"; j["vertexCount"] = stampData_.size(); + // Scrub NaN samples on save — nlohmann::json throws on non-finite + // serialization, which would abort the entire save. + auto san = [](float x) { return std::isfinite(x) ? x : 0.0f; }; nlohmann::json verts = nlohmann::json::array(); for (const auto& sv : stampData_) - verts.push_back({sv.dx, sv.dy, sv.height}); + verts.push_back({san(sv.dx), san(sv.dy), san(sv.height)}); j["vertices"] = verts; namespace fs = std::filesystem;