Prevent crash by guarding creatureData against nullptr

This commit is contained in:
qudzy
2022-06-01 21:46:10 +02:00
parent 66e77e324d
commit 1d7c709b52

View File

@@ -53,10 +53,15 @@ CDPairCalculatedValue::CDPairCalculatedValue(PlayerbotAI* botAI, std::string con
std::string const CDPairCalculatedValue::Format() std::string const CDPairCalculatedValue::Format()
{ {
CreatureData const* creatureData = Calculate(); CreatureData const* creatureData = Calculate();
if (creatureData)
{
CreatureTemplate const* bmTemplate = sObjectMgr->GetCreatureTemplate(creatureData->id1); CreatureTemplate const* bmTemplate = sObjectMgr->GetCreatureTemplate(creatureData->id1);
return bmTemplate ? bmTemplate->Name : "<none>"; return bmTemplate ? bmTemplate->Name : "<none>";
} }
return "<none>";
}
CDPairListCalculatedValue::CDPairListCalculatedValue(PlayerbotAI* botAI, std::string const name, int32 checkInterval) : CDPairListCalculatedValue::CDPairListCalculatedValue(PlayerbotAI* botAI, std::string const name, int32 checkInterval) :
CalculatedValue<std::vector<CreatureData const*>>(botAI, name, checkInterval) CalculatedValue<std::vector<CreatureData const*>>(botAI, name, checkInterval)
{ {