From 7a5258853a5002ce5eb3415ea80a954318e68e5b Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 29 Dec 2022 14:28:38 +0200 Subject: [PATCH] Fix potential access violation due to iterator invalidation --- client/battle/BattleStacksController.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/battle/BattleStacksController.cpp b/client/battle/BattleStacksController.cpp index 00c42155c..3bbbba7dd 100644 --- a/client/battle/BattleStacksController.cpp +++ b/client/battle/BattleStacksController.cpp @@ -348,7 +348,11 @@ void BattleStacksController::update() void BattleStacksController::updateBattleAnimations() { - for (auto & elem : currentAnimations) + // operate on copy - to prevent potential iterator invalidation due to push_back's + // FIXME? : remove remaining calls to addNewAnim from BattleAnimation::nextFrame (only Catapult explosion at the time of writing) + auto copiedVector = currentAnimations; + + for (auto & elem : copiedVector) { if (!elem) continue;