From e896d0b0125b48e12d43d99ace4498e56d968d50 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 27 Feb 2012 23:44:35 +0100 Subject: Fixed bug with erasing the last status effect It's not nice to use ++ on an iterator that may be std::map::end(), in my case this caused it to hang indefinitely. Reviewed-by: Yohann Ferreira --- src/game-server/being.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 6fce57e8..408b8fc0 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -669,8 +669,10 @@ void Being::update() for (AttributeMap::iterator it = mAttributes.begin(); it != mAttributes.end(); ++it) + { if (it->second.tick()) updateDerivedAttributes(it->first); + } // Update and run status effects StatusEffects::iterator it = mStatus.begin(); @@ -682,10 +684,14 @@ void Being::update() if (it->second.time <= 0 || mAction == DEAD) { - mStatus.erase(it); - it = mStatus.begin(); + StatusEffects::iterator removeIt = it; + it++; // bring this iterator to the safety of the next element + mStatus.erase(removeIt); + } + else + { + it++; } - it++; } // Check if being died -- cgit v1.2.3-70-g09d2