From f7e07ea1e11bc0306f440161d8c8920379c14ee0 Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Sat, 6 Aug 2016 14:06:03 +0200 Subject: [PATCH] Several bugfixes in closure procedure. Several bugfixes in closure procedure. --- source/luaSound.cpp | 46 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/source/luaSound.cpp b/source/luaSound.cpp index 201cde5..d117033 100644 --- a/source/luaSound.cpp +++ b/source/luaSound.cpp @@ -90,6 +90,20 @@ static int audioThread(unsigned int args, void* arg){ mus = new_track; new_track = NULL; + // Checking if a new track is available + if (mus == NULL){ + + //If we enter here, we probably are in the exiting procedure + if (mustExit){ + exited++; + if (exited < AUDIO_CHANNELS) sceKernelSignalSema(Audio_Mutex, 1); + else mustExit = false; + sceAudioOutReleasePort(ch); + sceKernelExitThread(0); + } + + } + // Initializing audio decoder audio_decoder[id] = AudioDecoder::Create(mus->handle, "Track"); audio_decoder[id]->Open(mus->handle); @@ -105,25 +119,35 @@ static int audioThread(unsigned int args, void* arg){ for (;;){ // Check if the music must be paused - if (mus->pauseTrigger){ + if (mus->pauseTrigger || mustExit){ - // Check if the thread must be closed - if (mustExit){ - exited++; - if (exited < AUDIO_CHANNELS) sceKernelSignalSema(Audio_Mutex, 1); - else mustExit = false; - sceAudioOutReleasePort(ch); - sceKernelExitThread(0); - } - // Check if the music must be closed if (mus->closeTrigger){ free(mus->audiobuf); free(mus->audiobuf2); audio_decoder[id].reset(); free(mus); + mus = NULL; availThreads[id] = true; - break; + if (!mustExit) break; + } + + // Check if the thread must be closed + if (mustExit){ + + // Check if the audio stream has already been closed + if (mus != NULL){ + mus->closeTrigger = true; + continue; + } + + // Recursively closing all the threads + exited++; + if (exited < AUDIO_CHANNELS) sceKernelSignalSema(Audio_Mutex, 1); + else mustExit = false; + sceAudioOutReleasePort(ch); + sceKernelExitThread(0); + } mus->isPlaying = !mus->isPlaying;