mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-19 17:05:44 +01:00
Core/Units: Fixed crash happening when charm was removed by its own charmed AI during update
This commit is contained in:
@@ -9417,7 +9417,6 @@ void Unit::SetAI(UnitAI* newAI)
|
||||
|
||||
void Unit::ScheduleAIChange()
|
||||
{
|
||||
ASSERT(!m_aiLocked, "Attempt to schedule AI change during AI update tick");
|
||||
bool const charmed = IsCharmed();
|
||||
// if charm is applied, we can't have disabled AI already, and vice versa
|
||||
if (charmed)
|
||||
@@ -9427,15 +9426,20 @@ void Unit::ScheduleAIChange()
|
||||
|
||||
if (charmed)
|
||||
i_disabledAI = std::move(i_AI);
|
||||
else if (m_aiLocked)
|
||||
{
|
||||
ASSERT(!i_lockedAILifetimeExtension, "Attempt to schedule multiple charm AI changes during one update");
|
||||
i_lockedAILifetimeExtension = std::move(i_AI); // AI needs to live just a bit longer to finish its UpdateAI
|
||||
}
|
||||
else
|
||||
i_AI.reset();
|
||||
}
|
||||
|
||||
void Unit::RestoreDisabledAI()
|
||||
{
|
||||
ASSERT(!m_aiLocked, "Attempt to restore AI during UpdateAI tick");
|
||||
ASSERT((GetTypeId() == TYPEID_PLAYER) || i_disabledAI, "Attempt to restore disabled AI on creature without disabled AI");
|
||||
i_AI = std::move(i_disabledAI);
|
||||
i_lockedAILifetimeExtension.reset();
|
||||
}
|
||||
|
||||
void Unit::AddToWorld()
|
||||
|
||||
@@ -1791,7 +1791,9 @@ class TC_GAME_API Unit : public WorldObject
|
||||
|
||||
void UpdateCharmAI();
|
||||
void RestoreDisabledAI();
|
||||
std::unique_ptr<UnitAI> i_AI, i_disabledAI;
|
||||
std::unique_ptr<UnitAI> i_AI;
|
||||
std::unique_ptr<UnitAI> i_disabledAI;
|
||||
std::unique_ptr<UnitAI> i_lockedAILifetimeExtension; // yes, this lifetime extension is terrible
|
||||
bool m_aiLocked;
|
||||
|
||||
std::unordered_set<AbstractFollower*> m_followingMe;
|
||||
|
||||
Reference in New Issue
Block a user