From 4170ab62c0931fd38d0fe7ed7ff521642eb3dda7 Mon Sep 17 00:00:00 2001 From: Fabian Stein Date: Thu, 29 Dec 2016 15:21:41 +0100 Subject: Fixed entity effect ticking (#3497) Fixes #3386 --- src/Entities/Pawn.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index a073dc9a7..b7fab31c3 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -48,6 +48,8 @@ void cPawn::Destroyed() void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { + std::vector EffectsToTick; + // Iterate through this entity's applied effects for (tEffectMap::iterator iter = m_EntityEffects.begin(); iter != m_EntityEffects.end();) { @@ -55,7 +57,8 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) cEntityEffect::eType EffectType = iter->first; cEntityEffect * Effect = iter->second; - Effect->OnTick(*this); + // Call OnTick later to make sure the iterator won't be invalid + EffectsToTick.push_back(Effect); // Iterates (must be called before any possible erasure) ++iter; @@ -69,6 +72,12 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // TODO: Check for discrepancies between client and server effect values } + + for (auto * Effect : EffectsToTick) + { + Effect->OnTick(*this); + } + class Pusher : public cEntityCallback { public: -- cgit v1.2.3