[Add] More complete error checking for audio framework [sound].
This commit is contained in:
parent
439fce48c8
commit
6a02e903a5
22
src/sound.c
22
src/sound.c
@ -60,6 +60,8 @@ static void sound_free(alSound* snd);
|
|||||||
static int voice_getSource(alVoice* voc);
|
static int voice_getSource(alVoice* voc);
|
||||||
|
|
||||||
int sound_init(void) {
|
int sound_init(void) {
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
sound_lock = SDL_CreateMutex();
|
sound_lock = SDL_CreateMutex();
|
||||||
|
|
||||||
SDL_mutexP(sound_lock);
|
SDL_mutexP(sound_lock);
|
||||||
@ -69,14 +71,16 @@ int sound_init(void) {
|
|||||||
al_device = alcOpenDevice(NULL);
|
al_device = alcOpenDevice(NULL);
|
||||||
if(al_device == NULL) {
|
if(al_device == NULL) {
|
||||||
WARN("Unable to open default sound device");
|
WARN("Unable to open default sound device");
|
||||||
return -1;
|
ret = -1;
|
||||||
|
goto snderr_dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the OpenAL context.
|
// Create the OpenAL context.
|
||||||
al_context = alcCreateContext(al_device, NULL);
|
al_context = alcCreateContext(al_device, NULL);
|
||||||
if(al_context == NULL) {
|
if(al_context == NULL) {
|
||||||
WARN("Unable to create OpenAL context");
|
WARN("Unable to create OpenAL context");
|
||||||
return -2;
|
ret = -2;
|
||||||
|
goto snderr_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the errors.
|
// Clear the errors.
|
||||||
@ -85,7 +89,8 @@ int sound_init(void) {
|
|||||||
// Set active context.
|
// Set active context.
|
||||||
if(alcMakeContextCurrent(al_context)==AL_FALSE) {
|
if(alcMakeContextCurrent(al_context)==AL_FALSE) {
|
||||||
WARN("Failure to set default context");
|
WARN("Failure to set default context");
|
||||||
return -4;
|
ret = -4;
|
||||||
|
goto snderr_act;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the master gain.
|
// Set the master gain.
|
||||||
@ -104,6 +109,17 @@ int sound_init(void) {
|
|||||||
music_player = SDL_CreateThread(music_thread, NULL);
|
music_player = SDL_CreateThread(music_thread, NULL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
snderr_act:
|
||||||
|
alcDestroyContext(al_context);
|
||||||
|
snderr_ctx:
|
||||||
|
al_context = NULL;
|
||||||
|
alcCloseDevice(al_device);
|
||||||
|
snderr_dev:
|
||||||
|
al_device = NULL;
|
||||||
|
SDL_mutexV(sound_lock);
|
||||||
|
SDL_DestroyMutex(sound_lock);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user