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

Fix potential crash on loading mod with invalid handler name

This commit is contained in:
Ivan Savenko 2023-10-26 15:32:13 +03:00
parent ab7caa0777
commit 6337b0d3b9

View File

@ -193,13 +193,16 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
assert(identifier.find(':') == std::string::npos);
assert(!scope.empty());
std::string handler = obj->handlerName;
if(!handlerConstructors.count(obj->handlerName))
{
logGlobal->error("Handler with name %s was not found!", obj->handlerName);
return nullptr;
logMod->error("Handler with name %s was not found!", obj->handlerName);
// workaround for potential crash - if handler does not exists, continue with generic handler that is used for objects without any custom logc
handler = "generic";
assert(handlerConstructors.count(handler) != 0);
}
auto createdObject = handlerConstructors.at(obj->handlerName)();
auto createdObject = handlerConstructors.at(handler)();
createdObject->modScope = scope;
createdObject->typeName = obj->identifier;;