Fix GetGuidValue crash

This commit is contained in:
Yunfan Li
2024-02-10 12:10:52 +08:00
parent db1adf35c1
commit 4091ba3e5a
3 changed files with 27 additions and 1 deletions

View File

@@ -113,3 +113,27 @@ std::string const ObjectGuidListCalculatedValue::Format()
return out.str();
}
Unit* UnitCalculatedValue::Get()
{
if (checkInterval < 2) {
PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
if (pmo)
pmo->finish();
} else {
time_t now = getMSTime();
if (!lastCheckTime || now - lastCheckTime >= checkInterval)
{
lastCheckTime = now;
PerformanceMonitorOperation* pmo = sPerformanceMonitor->start(PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
if (pmo)
pmo->finish();
}
}
// Prevent crashing by InWorld check
if (value && value->IsInWorld())
return value;
return nullptr;
}

View File

@@ -9,6 +9,7 @@
#include "ObjectGuid.h"
#include "PerformanceMonitor.h"
#include "Timer.h"
#include "Unit.h"
#include <time.h>
@@ -257,6 +258,7 @@ class UnitCalculatedValue : public CalculatedValue<Unit*>
UnitCalculatedValue(PlayerbotAI* botAI, std::string const name = "value", int32 checkInterval = 1);
std::string const Format() override;
Unit* Get() override;
};
class CDPairCalculatedValue : public CalculatedValue<CreatureData const*>

View File

@@ -9,7 +9,7 @@
bool NeedCureTrigger::IsActive()
{
Unit* target = GetTarget();
return target && botAI->HasAuraToDispel(target, dispelType);
return target && target->IsInWorld() && botAI->HasAuraToDispel(target, dispelType);
}
Value<Unit*>* PartyMemberNeedCureTrigger::GetTargetValue()