1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fixed possible crash on invalid town building name

This commit is contained in:
Ivan Savenko 2023-08-06 13:30:20 +03:00
parent a4ff408c9d
commit 8b0f9c86f8

View File

@ -1183,11 +1183,19 @@ void CTownHandler::initializeRequirements()
{
if (node.Vector().size() > 1)
{
logMod->warn("Unexpected length of town buildings requirements: %d", node.Vector().size());
logMod->warn("Entry contains: ");
logMod->warn(node.toJson());
logMod->error("Unexpected length of town buildings requirements: %d", node.Vector().size());
logMod->error("Entry contains: ");
logMod->error(node.toJson());
}
return BuildingID(VLC->modh->identifiers.getIdentifier(requirement.town->getBuildingScope(), node.Vector()[0]).value());
auto index = VLC->modh->identifiers.getIdentifier(requirement.town->getBuildingScope(), node[0]);
if (!index.has_value())
{
logMod->error("Unknown building in town buildings: %s", node[0].String());
return BuildingID::NONE;
}
return BuildingID(index.value());
});
}
requirementsToLoad.clear();