mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-15 09:50:27 +00:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user