From 870d0d23a31f7c3a4d0abc37923b9b7afb2fb8a9 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sun, 14 Jun 2015 10:33:31 +0200 Subject: SHERLOCK: Add mutex to Sherlock MIDI parser Hopefully this will put a stop to random crashes when music starts and/or stops. I'm never quite sure just how much locking is necessary, though... --- engines/sherlock/music.cpp | 6 ++++++ engines/sherlock/music.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/engines/sherlock/music.cpp b/engines/sherlock/music.cpp index 1d4c6e08ee..470c6fafb3 100644 --- a/engines/sherlock/music.cpp +++ b/engines/sherlock/music.cpp @@ -21,6 +21,7 @@ */ #include "common/config-manager.h" +#include "common/mutex.h" #include "sherlock/sherlock.h" #include "sherlock/music.h" #include "sherlock/scalpel/drivers/mididriver.h" @@ -62,11 +63,14 @@ MidiParser_SH::MidiParser_SH() { } MidiParser_SH::~MidiParser_SH() { + Common::StackLock lock(_mutex); unloadMusic(); _driver = NULL; } void MidiParser_SH::parseNextEvent(EventInfo &info) { + Common::StackLock lock(_mutex); + // warning("parseNextEvent"); // there is no delta right at the start of the music data @@ -165,6 +169,8 @@ void MidiParser_SH::parseNextEvent(EventInfo &info) { } bool MidiParser_SH::loadMusic(byte *data, uint32 size) { + Common::StackLock lock(_mutex); + debugC(kDebugLevelMusic, "Music: loadMusic()"); unloadMusic(); diff --git a/engines/sherlock/music.h b/engines/sherlock/music.h index 04b9dbd98e..2ebede9ea3 100644 --- a/engines/sherlock/music.h +++ b/engines/sherlock/music.h @@ -30,6 +30,7 @@ // for 3DO digital music #include "audio/audiostream.h" #include "audio/mixer.h" +#include "common/mutex.h" namespace Sherlock { @@ -41,6 +42,7 @@ public: ~MidiParser_SH(); protected: + Common::Mutex _mutex; virtual void parseNextEvent(EventInfo &info); uint8 _beats; -- cgit v1.2.3