mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-09 18:43:51 +00:00
fix(objects): scrub NaN/inf floats at save time
Same json-serialization-safety fix as for NPC and WOT saves. Object position/rotation NaN would abort the entire objects.json save and lose all placement work in the session.
This commit is contained in:
parent
999388b805
commit
49feb8b9f6
1 changed files with 7 additions and 3 deletions
|
|
@ -279,14 +279,18 @@ void ObjectPlacer::undoLastPlace() {
|
||||||
bool ObjectPlacer::saveToFile(const std::string& path) const {
|
bool ObjectPlacer::saveToFile(const std::string& path) const {
|
||||||
std::filesystem::create_directories(std::filesystem::path(path).parent_path());
|
std::filesystem::create_directories(std::filesystem::path(path).parent_path());
|
||||||
|
|
||||||
|
// nlohmann::json throws on NaN/inf serialization. Scrub on the way
|
||||||
|
// out so a bad in-memory transform can't kill the whole save.
|
||||||
|
auto san = [](float x) { return std::isfinite(x) ? x : 0.0f; };
|
||||||
|
auto sanScale = [](float x) { return (std::isfinite(x) && x > 0.0f) ? x : 1.0f; };
|
||||||
nlohmann::json arr = nlohmann::json::array();
|
nlohmann::json arr = nlohmann::json::array();
|
||||||
for (const auto& o : objects_) {
|
for (const auto& o : objects_) {
|
||||||
arr.push_back({
|
arr.push_back({
|
||||||
{"type", static_cast<int>(o.type)},
|
{"type", static_cast<int>(o.type)},
|
||||||
{"path", o.path},
|
{"path", o.path},
|
||||||
{"pos", {o.position.x, o.position.y, o.position.z}},
|
{"pos", {san(o.position.x), san(o.position.y), san(o.position.z)}},
|
||||||
{"rot", {o.rotation.x, o.rotation.y, o.rotation.z}},
|
{"rot", {san(o.rotation.x), san(o.rotation.y), san(o.rotation.z)}},
|
||||||
{"scale", o.scale},
|
{"scale", sanScale(o.scale)},
|
||||||
{"uniqueId", o.uniqueId}
|
{"uniqueId", o.uniqueId}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue