AGOS: Deadlock when shutting down game, at least with the MT-32 emulator
|Reported by:||eriktorbjorn||Owned by:||athrxx|
I've noticed several times that when I shut down an AGOS games that uses the MT-32 emulator, it deadlocks. Of course, such problems can be tricky to debug. I think the sequence of events goes like this:
- AGOS::~MidiPlayer() is called, but has not yet had the time to lock _mutex.
- The audio thread calls AGOS::MidiPlayer::onTimer(), which has not yet had the time to lock _mutex.
- ~MidiPlayer() locks _mutex, leaving onTimer() waiting.
- ~MidiPlayer() calls _driver->close()
- MidiDriver_MT32::close() calls _mixer->stopHandle() which never terminates.
I think stopHandle() may be waiting for readBuffer() to finish, but it never does because onTimer() is blocked. But I'm not quite sure.
I've seen this happen with the DOS talkie version of Simon the Sorcerer 1, and I also had it lock up with Elvira 2, probably for the same reason.