[Fix issue #1527] : startup crash in tank target selection — add TOCTOU & null-safety guards (#1532)

* Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks

* Fix Issue 1528

* Fix Issue #1527
This commit is contained in:
Alex Dcnh
2025-08-11 17:00:31 +02:00
committed by GitHub
parent 2e0a161623
commit c6b0424c29
2 changed files with 144 additions and 6 deletions

View File

@@ -14,7 +14,7 @@
Unit* FindTargetStrategy::GetResult() { return result; }
Unit* TargetValue::FindTarget(FindTargetStrategy* strategy)
/*Unit* TargetValue::FindTarget(FindTargetStrategy* strategy)
{
GuidVector attackers = botAI->GetAiObjectContext()->GetValue<GuidVector>("attackers")->Get();
for (ObjectGuid const guid : attackers)
@@ -27,6 +27,28 @@ Unit* TargetValue::FindTarget(FindTargetStrategy* strategy)
strategy->CheckAttacker(unit, &ThreatMgr);
}
return strategy->GetResult();
}*/
Unit* TargetValue::FindTarget(FindTargetStrategy* strategy)
{
// [Crash fix] The very first AI tick can occur before everything is "in world".
// Filter out units that are non-living / being removed / out of world.
AiObjectContext* ctx = botAI->GetAiObjectContext();
if (!ctx)
return strategy->GetResult();
GuidVector attackers = ctx->GetValue<GuidVector>("attackers")->Get();
for (ObjectGuid const& guid : attackers)
{
Unit* unit = botAI->GetUnit(guid);
if (!unit || !unit->IsAlive() || !unit->IsInWorld() || unit->IsDuringRemoveFromWorld())
continue;
ThreatMgr& threatMgrRef = unit->GetThreatMgr();
strategy->CheckAttacker(unit, &threatMgrRef);
}
return strategy->GetResult();
}