From 721efb2ecba21235849e1f68b1f7e5859c7ae4e0 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 06:44:30 -0700 Subject: [PATCH] fix(zone): clamp manifest audio volumes and reject NaN baseHeight on load A user-edited zone.json could carry NaN/inf or out-of-range volumes which would silently corrupt terrain elevation or produce silent / clipping audio. Now baseHeight defaults back to 100 if non-finite, and music/ambience volumes clamp to [0,1] with NaN fallbacks. --- tools/editor/zone_manifest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/editor/zone_manifest.cpp b/tools/editor/zone_manifest.cpp index 2a1bbcea..afa420ca 100644 --- a/tools/editor/zone_manifest.cpp +++ b/tools/editor/zone_manifest.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include namespace wowee { namespace editor { @@ -85,6 +87,9 @@ bool ZoneManifest::load(const std::string& path) { description = j.value("description", ""); mapId = j.value("mapId", 9000u); baseHeight = j.value("baseHeight", 100.0f); + // Sanitize edited values — baseHeight propagates into terrain mesh + // generation; volume into audio mixer. + if (!std::isfinite(baseHeight)) baseHeight = 100.0f; hasCreatures = j.value("hasCreatures", false); tiles.clear(); @@ -112,6 +117,12 @@ bool ZoneManifest::load(const std::string& path) { ambienceNight = a.value("ambienceNight", ""); musicVolume = a.value("musicVolume", 0.7f); ambienceVolume = a.value("ambienceVolume", 0.5f); + // Clamp volumes to [0, 1] and reject NaN — mixer would otherwise + // produce silent or clipping output. + if (!std::isfinite(musicVolume)) musicVolume = 0.7f; + if (!std::isfinite(ambienceVolume)) ambienceVolume = 0.5f; + musicVolume = std::clamp(musicVolume, 0.0f, 1.0f); + ambienceVolume = std::clamp(ambienceVolume, 0.0f, 1.0f); } return !mapName.empty();