diff --git a/libraries/zmusic/musicformats/music_midi.cpp b/libraries/zmusic/musicformats/music_midi.cpp index c76b13e4d1..614081e894 100644 --- a/libraries/zmusic/musicformats/music_midi.cpp +++ b/libraries/zmusic/musicformats/music_midi.cpp @@ -570,10 +570,12 @@ bool MIDIStreamer::IsPlaying() { if (m_Status != STATE_Stopped && (MIDI == NULL || (EndQueued != 0 && EndQueued < 4))) { + std::lock_guard lock(CritSec); Stop(); } if (m_Status != STATE_Stopped && !MIDI->IsOpen()) { + std::lock_guard lock(CritSec); Stop(); } return m_Status != STATE_Stopped; @@ -695,7 +697,11 @@ void MIDIStreamer::Callback(void *userdata) void MIDIStreamer::Update() { - if (MIDI != nullptr && !MIDI->Update()) Stop(); + if (MIDI != nullptr && !MIDI->Update()) + { + std::lock_guard lock(CritSec); + Stop(); + } } //========================================================================== diff --git a/libraries/zmusic/zmusic/zmusic.cpp b/libraries/zmusic/zmusic/zmusic.cpp index 50eb781633..7d6b18f8a3 100644 --- a/libraries/zmusic/zmusic/zmusic.cpp +++ b/libraries/zmusic/zmusic/zmusic.cpp @@ -340,28 +340,24 @@ void ZMusic_Start(MusInfo *song, int subsong, bool loop) void ZMusic_Pause(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Pause(); } void ZMusic_Resume(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Resume(); } void ZMusic_Update(MusInfo *song) { if (!song) return; - std::lock_guard lock(song->CritSec); song->Update(); } bool ZMusic_IsPlaying(MusInfo *song) { if (!song) return false; - std::lock_guard lock(song->CritSec); return song->IsPlaying(); }