all repos — fluxbox @ fa5202c1202cda17a956f83221c9ef9ed72cbfd2

custom fork of the fluxbox windowmanager

accepted patch #1057446, improved iterator in timer-code
akir akir
commit

fa5202c1202cda17a956f83221c9ef9ed72cbfd2

parent

fa1692180e18f95c9e8f46d37c5bb8797eeebd5a

1 files changed, 15 insertions(+), 6 deletions(-)

jump to
M src/FbTk/Timer.ccsrc/FbTk/Timer.cc

@@ -163,7 +163,7 @@ gettimeofday(&now, 0);

//must check end ...the timer might remove //it self from the list (should be fixed in the future) - for(it = m_timerlist.begin(); it != m_timerlist.end(); ++it) { + for(it = m_timerlist.begin(); it != m_timerlist.end(); ) { //This is to make sure we don't get an invalid iterator //when we do fireTimeout Timer &t = *(*it);

@@ -178,12 +178,21 @@ break;

t.fireTimeout(); // restart the current timer so that the start time is updated - if (! t.doOnce()) + if (! t.doOnce()) { t.start(); - else { - t.stop(); - it--; - } + + // Note that this mustn't be done if we're deleting the + // entry from the list, so therefore it's not in the update + // section of the for loop + it++; + } else { + // Since the default stop behaviour results in the timer + // being removed, we must remove it here, so that the iterator + // lives well. Another option would be to add it to another + // list, and then just go through that list and stop them all. + it = m_timerlist.erase(it); + t.stop(); + } } last_time = time(0);