From b13723305dc1038b16db6a17d2eb44f7941064ba Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 18 Dec 2022 16:04:57 +0200 Subject: [PATCH] Better error reporting for usages of invalid terrain in mods TODO: switch to proper mechanism via identifier requests --- lib/mapObjects/ObjectTemplate.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/ObjectTemplate.cpp b/lib/mapObjects/ObjectTemplate.cpp index 9caec2379..7598aabe8 100644 --- a/lib/mapObjects/ObjectTemplate.cpp +++ b/lib/mapObjects/ObjectTemplate.cpp @@ -287,7 +287,15 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain) if(withTerrain && !node["allowedTerrains"].isNull()) { for(auto& entry : node["allowedTerrains"].Vector()) - allowedTerrains.insert(VLC->terrainTypeHandler->getInfoByName(entry.String())->id); + { + try { + allowedTerrains.insert(VLC->terrainTypeHandler->getInfoByName(entry.String())->id); + } + catch (const std::out_of_range & ) + { + logGlobal->warn("Failed to find terrain %s for object %s", entry.String(), animationFile); + } + } } else { @@ -300,7 +308,7 @@ void ObjectTemplate::readJson(const JsonNode &node, const bool withTerrain) } if(withTerrain && allowedTerrains.empty()) - logGlobal->warn("Loaded template without allowed terrains!"); + logGlobal->warn("Loaded template %s without allowed terrains!", animationFile); auto charToTile = [&](const char & ch) -> ui8 {