From 9cb01a79046fce3f76835bb68bf66e4f3079e4bc Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Sat, 16 May 2020 09:06:03 +0000 Subject: Fixes/3.3.5 aura infinite loop (#24631) * Core/Auras: Attempt to fix infinite loop with aura 18950 on map unload * Core/Auras: Log a detailed error and assert when failing to remove all auras after a few tries * Code cleanup * Fix build warnings * Fix more build warnings (cherry picked from commit bd2d60c2676a1d7e843a2a5673b8216bad0768c7) --- src/server/game/Entities/Unit/Unit.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/server/game/Entities') diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 6537c31c890..c1ff6556ed4 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -4035,7 +4035,7 @@ void Unit::RemoveAllAuras() { // this may be a dead loop if some events on aura remove will continiously apply aura on remove // we want to have all auras removed, so use your brain when linking events - while (!m_appliedAuras.empty() || !m_ownedAuras.empty()) + for (int counter = 0; !m_appliedAuras.empty() || !m_ownedAuras.empty(); counter++) { AuraApplicationMap::iterator aurAppIter; for (aurAppIter = m_appliedAuras.begin(); aurAppIter != m_appliedAuras.end();) @@ -4044,6 +4044,37 @@ void Unit::RemoveAllAuras() AuraMap::iterator aurIter; for (aurIter = m_ownedAuras.begin(); aurIter != m_ownedAuras.end();) RemoveOwnedAura(aurIter); + + const int maxIteration = 50; + // give this loop a few tries, if there are still auras then log as much information as possible + if (counter >= maxIteration) + { + std::stringstream sstr; + sstr << "Unit::RemoveAllAuras() iterated " << maxIteration << " times already but there are still " + << m_appliedAuras.size() << " m_appliedAuras and " << m_ownedAuras.size() << " m_ownedAuras. Details:" << "\n"; + sstr << GetDebugInfo() << "\n"; + + if (!m_appliedAuras.empty()) + { + sstr << "m_appliedAuras:" << "\n"; + + for (std::pair& auraAppPair : m_appliedAuras) + sstr << auraAppPair.second->GetDebugInfo() << "\n"; + } + + if (!m_ownedAuras.empty()) + { + sstr << "m_ownedAuras:" << "\n"; + + for (std::pair& auraPair : m_ownedAuras) + sstr << auraPair.second->GetDebugInfo() << "\n"; + } + + TC_LOG_ERROR("entities.unit", "%s", sstr.str().c_str()); + ABORT_MSG("%s", sstr.str().c_str()); + + break; + } } } -- cgit v1.2.3