diff options
author | glx <glx@openttd.org> | 2007-08-31 23:29:53 +0000 |
---|---|---|
committer | glx <glx@openttd.org> | 2007-08-31 23:29:53 +0000 |
commit | dc4c52a3133cea06514f38bb06e0d3ddd7734903 (patch) | |
tree | 41c85cf058141282271094ee671787af6e1abc5b /src/music | |
parent | e128170b1fec867045aa7ef194ac9fc8161eda1f (diff) | |
download | openttd-dc4c52a3133cea06514f38bb06e0d3ddd7734903.tar.xz |
(svn r11029) -Fix [FS#1164]: win32 midi doesn't stop when closing openttd
Diffstat (limited to 'src/music')
-rw-r--r-- | src/music/win32_m.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/music/win32_m.cpp b/src/music/win32_m.cpp index 470572254..35e7cdef3 100644 --- a/src/music/win32_m.cpp +++ b/src/music/win32_m.cpp @@ -11,6 +11,7 @@ static struct { bool playing; int new_vol; HANDLE wait_obj; + HANDLE thread; UINT_PTR devid; char start_song[260]; } _midi; @@ -84,8 +85,6 @@ static bool MidiIntIsSongPlaying() static DWORD WINAPI MidiThread(LPVOID arg) { - _midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL); - do { char *s; int vol; @@ -102,7 +101,7 @@ static DWORD WINAPI MidiThread(LPVOID arg) s[0] = '\0'; // Delay somewhat in case we don't manage to play. - if (!_midi.playing) Sleep(5000); + if (!_midi.playing) WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 5000); } if (_midi.stop_song && _midi.playing) { @@ -116,14 +115,13 @@ static DWORD WINAPI MidiThread(LPVOID arg) WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000); } while (!_midi.terminate); - DeleteObject(_midi.wait_obj); + MidiIntStopSong(); return 0; } const char *MusicDriver_Win32::Start(const char * const *parm) { MIDIOUTCAPS midicaps; - DWORD threadId; UINT nbdev; UINT_PTR dev; char buf[16]; @@ -143,7 +141,8 @@ const char *MusicDriver_Win32::Start(const char * const *parm) } } - if (CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId) == NULL) return "Failed to create thread"; + if (NULL == (_midi.wait_obj = CreateEvent(NULL, FALSE, FALSE, NULL))) return "Failed to create event"; + if (NULL == (_midi.thread = CreateThread(NULL, 8192, MidiThread, 0, 0, NULL))) return "Failed to create thread"; return NULL; } @@ -152,4 +151,7 @@ void MusicDriver_Win32::Stop() { _midi.terminate = true; SetEvent(_midi.wait_obj); + WaitForMultipleObjects(1, &_midi.thread, true, INFINITE); + CloseHandle(_midi.wait_obj); + CloseHandle(_midi.thread); } |