Dreamcast: Fix build from website crashing when going in-game

This commit is contained in:
UnknownShadow200 2024-04-26 11:58:23 +10:00
parent 084f1ecbaf
commit db9b620bc0

View File

@ -1305,6 +1305,7 @@ void Audio_FreeChunks(void** chunks, int numChunks) {
*#########################################################################################################################*/ *#########################################################################################################################*/
#include <kos.h> #include <kos.h>
/* TODO needs way more testing, especially with sounds */ /* TODO needs way more testing, especially with sounds */
static cc_bool valid_handles[SND_STREAM_MAX];
struct AudioBuffer { struct AudioBuffer {
int available; int available;
@ -1325,8 +1326,10 @@ cc_bool AudioBackend_Init(void) {
void AudioBackend_Tick(void) { void AudioBackend_Tick(void) {
// TODO is this really threadsafe with music? should this be done in Audio_Poll instead? // TODO is this really threadsafe with music? should this be done in Audio_Poll instead?
for (int i = 0; i < SND_STREAM_MAX; i++) for (int i = 0; i < SND_STREAM_MAX; i++)
snd_stream_poll(i); {
if (valid_handles[i]) snd_stream_poll(i);
}
} }
void AudioBackend_Free(void) { void AudioBackend_Free(void) {
@ -1367,6 +1370,7 @@ cc_result Audio_Init(struct AudioContext* ctx, int buffers) {
ctx->count = buffers; ctx->count = buffers;
ctx->bufHead = 0; ctx->bufHead = 0;
valid_handles[ctx->hnd] = true;
return 0; return 0;
} }
@ -1374,6 +1378,7 @@ void Audio_Close(struct AudioContext* ctx) {
if (ctx->count) { if (ctx->count) {
snd_stream_stop(ctx->hnd); snd_stream_stop(ctx->hnd);
snd_stream_destroy(ctx->hnd); snd_stream_destroy(ctx->hnd);
valid_handles[ctx->hnd] = false;
} }
ctx->hnd = SND_STREAM_INVALID; ctx->hnd = SND_STREAM_INVALID;