From db9b620bc0499a9e2d82ed67235cb01d00fd382d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 26 Apr 2024 11:58:23 +1000 Subject: [PATCH] Dreamcast: Fix build from website crashing when going in-game --- src/AudioBackend.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/AudioBackend.c b/src/AudioBackend.c index 975ad6cd1..5a4297c18 100644 --- a/src/AudioBackend.c +++ b/src/AudioBackend.c @@ -1305,6 +1305,7 @@ void Audio_FreeChunks(void** chunks, int numChunks) { *#########################################################################################################################*/ #include /* TODO needs way more testing, especially with sounds */ +static cc_bool valid_handles[SND_STREAM_MAX]; struct AudioBuffer { int available; @@ -1325,8 +1326,10 @@ cc_bool AudioBackend_Init(void) { void AudioBackend_Tick(void) { // TODO is this really threadsafe with music? should this be done in Audio_Poll instead? - for (int i = 0; i < SND_STREAM_MAX; i++) - snd_stream_poll(i); + for (int i = 0; i < SND_STREAM_MAX; i++) + { + if (valid_handles[i]) snd_stream_poll(i); + } } void AudioBackend_Free(void) { @@ -1367,6 +1370,7 @@ cc_result Audio_Init(struct AudioContext* ctx, int buffers) { ctx->count = buffers; ctx->bufHead = 0; + valid_handles[ctx->hnd] = true; return 0; } @@ -1374,6 +1378,7 @@ void Audio_Close(struct AudioContext* ctx) { if (ctx->count) { snd_stream_stop(ctx->hnd); snd_stream_destroy(ctx->hnd); + valid_handles[ctx->hnd] = false; } ctx->hnd = SND_STREAM_INVALID;