fix(Core/SpellQueue): Fix undefined behavior when processing SpellQueue. (#21459)

This commit is contained in:
Anton Popovichenko 2025-02-15 11:45:12 +01:00 committed by GitHub
parent ee69a569c4
commit 91da92f33f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2377,7 +2377,15 @@ void Player::ProcessSpellQueue()
if (CanExecutePendingSpellCastRequest(spellInfo))
{
ExecuteOrCancelSpellCastRequest(&request);
SpellQueue.pop_front(); // Remove from the queue
// ExecuteOrCancelSpellCastRequest() can lead to clearing the SpellQueue.
// Example scenario:
// Handling a spell → Dealing damage to yourself (e.g., spell_pri_vampiric_touch) →
// Killing yourself → Player::setDeathState() → SpellQueue.clear().
// Calling std::deque::pop_front() on an empty deque results in undefined behavior,
// so an additional check is added.
if (!SpellQueue.empty())
SpellQueue.pop_front();
}
else // If the first spell can't execute, stop processing
break;