mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-04-08 03:37:04 +00:00
Defensive coding around case where backend soundsystem is unavailable
This commit is contained in:
parent
2910b6180e
commit
c036c8dc84
@ -25,6 +25,11 @@ AudioBackend_s *audio_backend = NULL;
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
long audio_createSoundBuffer(INOUT AudioBuffer_s **audioBuffer, unsigned long numChannels) {
|
||||
*audioBuffer = NULL;
|
||||
|
||||
if (!audio_isAvailable) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
AudioSettings_s *settings = &audio_backend->systemSettings;
|
||||
|
||||
@ -59,18 +64,26 @@ bool audio_init(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (audioContext) {
|
||||
audio_backend->shutdown(&audioContext);
|
||||
}
|
||||
do {
|
||||
if (!audio_backend) {
|
||||
LOG("No backend audio available, cannot initialize soundcore");
|
||||
break;
|
||||
}
|
||||
|
||||
if (audioContext) {
|
||||
audio_backend->shutdown(&audioContext);
|
||||
}
|
||||
|
||||
long err = audio_backend->setup((AudioContext_s**)&audioContext);
|
||||
if (err) {
|
||||
LOG("Failed to create an audio context!");
|
||||
break;
|
||||
}
|
||||
|
||||
long err = audio_backend->setup((AudioContext_s**)&audioContext);
|
||||
if (err) {
|
||||
LOG("Failed to create an audio context!");
|
||||
} else {
|
||||
audio_isAvailable = true;
|
||||
}
|
||||
} while (0);
|
||||
|
||||
return err;
|
||||
return audio_isAvailable;
|
||||
}
|
||||
|
||||
void audio_shutdown(void) {
|
||||
@ -82,10 +95,16 @@ void audio_shutdown(void) {
|
||||
}
|
||||
|
||||
void audio_pause(void) {
|
||||
if (!audio_isAvailable) {
|
||||
return;
|
||||
}
|
||||
audio_backend->pause();
|
||||
}
|
||||
|
||||
void audio_resume(void) {
|
||||
if (!audio_isAvailable) {
|
||||
return;
|
||||
}
|
||||
audio_backend->resume();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user