Skip to content

Commit

Permalink
Several bugfixes in closure procedure.
Browse files Browse the repository at this point in the history
Several bugfixes in closure procedure.
  • Loading branch information
Rinnegatamante committed Aug 6, 2016
1 parent 8bb3d4a commit f7e07ea
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions source/luaSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit f7e07ea

Please sign in to comment.