From cea06991ebab97c72e9fd89a4bf63835bcf0de80 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:15:00 +0200 Subject: TIMER: Remove name of callback in removeTimerProc. This should fix #3389673 "LOOM: CD-Version crashes at start". It also fixes the same error showing up for me in Monkey CD. The doc changes in 4c7958450f628937270f claims the name is used for the event recorder, but as far as I can tell it is not used right now. Thus depending on how it is used the behavior of SCUMM removing and adding the same timer aagain *might* cause problems. In any way we need to remove the name in removeTimerProc, else RTL + launching the same game again would be broken too. --- backends/timer/default/default-timer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'backends/timer/default') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index efb3ec9ad9..28524bf3b5 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -161,4 +161,11 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { slot = slot->next; } } + + for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { + if (i->_value == callback) { + _callbacks.erase(i); + break; + } + } } -- cgit v1.2.3 From c443f113ed5729b88792d3b54b77d70033cb24dc Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:34:08 +0200 Subject: TIMER: Remove all names associated with a callback, since all callbacks are removed. This makes the name removal consistent with the timer proc removal. It seems we only allow a specific timer proc being added once anymore though. So this should not change too much right now. --- backends/timer/default/default-timer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'backends/timer/default') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 28524bf3b5..5b133660e0 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -163,9 +163,7 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { } for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { - if (i->_value == callback) { + if (i->_value == callback) _callbacks.erase(i); - break; - } } } -- cgit v1.2.3 From 930f626daba5de8ec0b42fd32ba7ddf107e7d95a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 10 Aug 2011 18:42:19 +0200 Subject: TIMER: Add a comment to explain why we remove the name in removeTimerProc. --- backends/timer/default/default-timer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'backends/timer/default') diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp index 5b133660e0..e1aadb62b8 100644 --- a/backends/timer/default/default-timer.cpp +++ b/backends/timer/default/default-timer.cpp @@ -162,6 +162,18 @@ void DefaultTimerManager::removeTimerProc(TimerProc callback) { } } + // We need to remove all names referencing the timer proc here. + // + // Else we run into troubles, when the client code removes and readds timer + // callbacks. + // + // Another issues occurs when one plays a game with ALSA as music driver, + // does RTL and starts a different engine game with ALSA as music driver. + // In this case the MPU401 code will add different timer procs with the + // same name, resulting in two different callbacks added with the same + // name and causing installTimerProc to error out. + // A good test case is running a SCUMM with ALSA output and then a KYRA + // game for example. for (TimerSlotMap::iterator i = _callbacks.begin(), end = _callbacks.end(); i != end; ++i) { if (i->_value == callback) _callbacks.erase(i); -- cgit v1.2.3