浏览代码

Fix possible crash on invalid spell

Ivan Savenko 1 年之前
父节点
当前提交
702fc8077d
共有 1 个文件被更改,包括 7 次插入4 次删除
  1. 7 4
      lib/CBonusTypeHandler.cpp

+ 7 - 4
lib/CBonusTypeHandler.cpp

@@ -76,10 +76,10 @@ std::string CBonusTypeHandler::bonusToString(const std::shared_ptr<Bonus> & bonu
 	if (text.find("${val}") != std::string::npos)
 	if (text.find("${val}") != std::string::npos)
 		boost::algorithm::replace_all(text, "${val}", std::to_string(bearer->valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
 		boost::algorithm::replace_all(text, "${val}", std::to_string(bearer->valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype))));
 
 
-	if (text.find("${subtype.creature}") != std::string::npos && bonus->subtype.as<CreatureID>() != CreatureID::NONE)
+	if (text.find("${subtype.creature}") != std::string::npos && bonus->subtype.as<CreatureID>().hasValue())
 		boost::algorithm::replace_all(text, "${subtype.creature}", bonus->subtype.as<CreatureID>().toCreature()->getNamePluralTranslated());
 		boost::algorithm::replace_all(text, "${subtype.creature}", bonus->subtype.as<CreatureID>().toCreature()->getNamePluralTranslated());
 
 
-	if (text.find("${subtype.spell}") != std::string::npos && bonus->subtype.as<SpellID>() != SpellID::NONE)
+	if (text.find("${subtype.spell}") != std::string::npos && bonus->subtype.as<SpellID>().hasValue())
 		boost::algorithm::replace_all(text, "${subtype.spell}", bonus->subtype.as<SpellID>().toSpell()->getNameTranslated());
 		boost::algorithm::replace_all(text, "${subtype.spell}", bonus->subtype.as<SpellID>().toSpell()->getNameTranslated());
 
 
 	return text;
 	return text;
@@ -95,8 +95,11 @@ ImagePath CBonusTypeHandler::bonusToGraphics(const std::shared_ptr<Bonus> & bonu
 	case BonusType::SPELL_IMMUNITY:
 	case BonusType::SPELL_IMMUNITY:
 	{
 	{
 		fullPath = true;
 		fullPath = true;
-		const CSpell * sp = bonus->subtype.as<SpellID>().toSpell();
-		fileName = sp->getIconImmune();
+		if (bonus->subtype.as<SpellID>().hasValue())
+		{
+			const CSpell * sp = bonus->subtype.as<SpellID>().toSpell();
+			fileName = sp->getIconImmune();
+		}
 		break;
 		break;
 	}
 	}
 	case BonusType::SPELL_DAMAGE_REDUCTION: //Spell damage reduction for all schools
 	case BonusType::SPELL_DAMAGE_REDUCTION: //Spell damage reduction for all schools