mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 09:33:51 +00:00
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.
This commit is contained in:
parent
185b7b522d
commit
721efb2ecb
1 changed files with 11 additions and 0 deletions
|
|
@ -5,6 +5,8 @@
|
|||
#include <filesystem>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue