summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-04 21:44:39 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-07-04 22:27:34 +0200
commita4cf1c8aec984e09c2814504c0383148cae9a8e9 (patch)
tree55b8d159bc703eddd39da525aa7a7e6e19a7a72d
parent9839ce006c5f5ac1dce0d4a1aab3aef790ffbc69 (diff)
downloadopenttd-a4cf1c8aec984e09c2814504c0383148cae9a8e9.tar.xz
Fix: Don't keep mutex locked while parsing MIDI data
-rw-r--r--src/music/win32_m.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp
index abc0fcd72..1447fd88a 100644
--- a/src/music/win32_m.cpp
+++ b/src/music/win32_m.cpp
@@ -312,10 +312,14 @@ void CALLBACK TimerCallback(UINT uTimerID, UINT, DWORD_PTR dwUser, DWORD_PTR, DW
void MusicDriver_Win32::PlaySong(const MusicSongInfo &song)
{
DEBUG(driver, 2, "Win32-MIDI: PlaySong: entry");
- std::lock_guard mutex_lock(_midi.lock);
- if (!_midi.next_file.LoadSong(song)) return;
+ MidiFile new_song;
+ if (!new_song.LoadSong(song)) return;
+ DEBUG(driver, 2, "Win32-MIDI: PlaySong: Loaded song");
+
+ std::lock_guard mutex_lock(_midi.lock);
+ _midi.next_file.MoveFrom(new_song);
_midi.next_segment.start = song.override_start;
_midi.next_segment.end = song.override_end;
_midi.next_segment.loop = song.loop;