From c744db3a86361a4f1d351fc28465ef53e07a83c9 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 7 Jan 2024 00:05:42 +0700 Subject: [PATCH] create mutex on music module init Avoid crashing when changing volume between tracks. --- src/i_oalmusic.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/i_oalmusic.c b/src/i_oalmusic.c index 4b3a9d0c..b8545253 100644 --- a/src/i_oalmusic.c +++ b/src/i_oalmusic.c @@ -249,6 +249,8 @@ static boolean I_OAL_InitMusic(int device) alSourcei(player.source, AL_SOURCE_SPATIALIZE_SOFT, AL_FALSE); } + music_lock = SDL_CreateMutex(); + music_initialized = true; return true; @@ -298,8 +300,6 @@ static void I_OAL_PlaySong(void *handle, boolean looping) return; } - music_lock = SDL_CreateMutex(); - player_thread_running = true; player_thread_handle = SDL_CreateThread(PlayerThread, NULL, NULL); if (player_thread_handle == NULL) @@ -325,7 +325,6 @@ static void I_OAL_StopSong(void *handle) player_thread_running = false; SDL_WaitThread(player_thread_handle, NULL); } - SDL_DestroyMutex(music_lock); alGetSourcei(player.source, AL_BUFFERS_PROCESSED, &processed); if (processed > 0) @@ -376,6 +375,8 @@ static void I_OAL_ShutdownMusic(void) memset(&player, 0, sizeof(stream_player_t)); + SDL_DestroyMutex(music_lock); + music_initialized = false; }