SAGA2: Delete timers on list removal

This commit is contained in:
a/ 2021-06-28 17:54:42 +09:00 committed by Eugene Sandulenko
parent b72d66a393
commit 1df171e36b
No known key found for this signature in database
GPG key ID: 014D387312D34F08
2 changed files with 7 additions and 1 deletions

View file

@ -1803,6 +1803,7 @@ bool GameObject::addTimer(TimerID id, int16 frameInterval) {
assert((*it)->getObject() == this);
if (newTimer->thisID() == (*it)->thisID()) {
delete *it;
timerList->_timers.erase(it);
break;
@ -1825,6 +1826,7 @@ void GameObject::removeTimer(TimerID id) {
if ((timerList = fetchTimerList(this)) != nullptr) {
for (Common::List<Timer *>::iterator it = timerList->_timers.begin(); it != timerList->_timers.end(); ++it) {
if ((*it)->thisID() == id) {
delete *it;
timerList->_timers.erase(it);
if (timerList->_timers.empty())

View file

@ -111,7 +111,11 @@ TimerList *fetchTimerList(GameObject *obj) {
//----------------------------------------------------------------------
// Check all active Timers
void checkTimers(void) {
for (Common::List<Timer *>::iterator it = g_vm->_timers.begin(); it != g_vm->_timers.end(); ++it) {
Common::List<Timer *>::iterator nextIt;
for (Common::List<Timer *>::iterator it = g_vm->_timers.begin(); it != g_vm->_timers.end(); it = nextIt) {
nextIt = it;
nextIt++;
if ((*it)->check()) {
debugC(2, kDebugTimers, "Timer tick for %p (%s): %p (duration %d)", (void *)(*it)->getObject(), (*it)->getObject()->objName(), (void *)(*it), (*it)->getInterval());
(*it)->reset();