From dd307749bea649c355ecf66ab7c879ab4dfcc769 Mon Sep 17 00:00:00 2001 From: Neirokan Date: Sat, 6 Nov 2021 00:31:41 +0300 Subject: [PATCH] Animation timeline erase fix --- engine/animation/Timeline.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/engine/animation/Timeline.cpp b/engine/animation/Timeline.cpp index 7109559..947b0e6 100644 --- a/engine/animation/Timeline.cpp +++ b/engine/animation/Timeline.cpp @@ -70,16 +70,12 @@ void Timeline::update() { return; } - // TODO: sometimes I catch an exception here: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) - for (auto&[listName, animationList] : _instance->_animations) { - if (animationList.empty()) { - /* - * TODO If you delete this line you will not catch an exception. - * Maybe something wrong with std::map::erase() - */ - _instance->_animations.erase(listName); + for (auto iter = _instance->_animations.begin(); iter != _instance->_animations.end(); ) { + if (iter->second.empty()) { + _instance->_animations.erase(iter++); continue; } + auto& animationList = iter->second; auto it = animationList.begin(); // If it the front animation is 'a_wait()' we should wait until waiting time is over @@ -98,6 +94,7 @@ void Timeline::update() { it++; } } + iter++; } }