Browse Source

Added workaround for crashes with outdated mods

Ivan Savenko 1 year ago
parent
commit
df78c9c6f1
2 changed files with 7 additions and 1 deletions
  1. 1 1
      lib/mapObjectConstructors/CommonConstructors.cpp
  2. 6 0
      lib/spells/effects/Summon.cpp

+ 1 - 1
lib/mapObjectConstructors/CommonConstructors.cpp

@@ -133,7 +133,7 @@ void CHeroInstanceConstructor::afterLoadFinalization()
 	{
 		filters[entry.first] = LogicalExpression<HeroTypeID>(entry.second, [](const JsonNode & node)
 		{
-			return HeroTypeID(VLC->identifiers()->getIdentifier("hero", node.Vector()[0]).value());
+			return HeroTypeID(VLC->identifiers()->getIdentifier("hero", node.Vector()[0]).value_or(-1));
 		});
 	}
 }

+ 6 - 0
lib/spells/effects/Summon.cpp

@@ -42,6 +42,12 @@ void Summon::adjustTargetTypes(std::vector<TargetType> & types) const
 
 bool Summon::applicable(Problem & problem, const Mechanics * m) const
 {
+	if (creature == CreatureID::NONE)
+	{
+		logMod->error("Attempt to summon non-existing creature!");
+		return m->adaptGenericProblem(problem);
+	}
+
 	if(exclusive)
 	{
 		//check if there are summoned creatures of other type