From 79ad6f086c2acad8384aa246348a8a7de29f184c Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 13 Apr 2021 16:20:38 +0200 Subject: [PATCH] Release sounds loaded by FMOD on shutdown, and check FMOD version upon startup --- engine/Quake/snd_dma.c | 4 ++-- engine/Quake/snd_fmod.c | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/engine/Quake/snd_dma.c b/engine/Quake/snd_dma.c index cc73134..a2e9945 100644 --- a/engine/Quake/snd_dma.c +++ b/engine/Quake/snd_dma.c @@ -65,8 +65,8 @@ portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES]; #endif // USE_FMOD #define MAX_SFX 1024 -static sfx_t *known_sfx = NULL; // hunk allocated [MAX_SFX] -static int num_sfx; +sfx_t *known_sfx = NULL; // hunk allocated [MAX_SFX] +int num_sfx; static sfx_t *ambient_sfx[NUM_AMBIENTS]; diff --git a/engine/Quake/snd_fmod.c b/engine/Quake/snd_fmod.c index 0ea79cb..64b2267 100644 --- a/engine/Quake/snd_fmod.c +++ b/engine/Quake/snd_fmod.c @@ -5,6 +5,8 @@ #include "fmod_errors.h" extern qboolean sound_started; // in snd_dma.c +extern sfx_t *known_sfx; +extern int num_sfx; FMOD_SYSTEM *fmod_system = NULL; static qboolean fmod_ownership = false; @@ -76,6 +78,12 @@ void S_Startup(void) return; } + if (version < FMOD_VERSION) + { + Con_Printf("Incorrect FMOD library version, expected: 0x%x, found: 0x%x", FMOD_VERSION, version); + return; + } + result = FMOD_System_GetDriver(fmod_system, &driver); if (result != FMOD_OK) { @@ -112,11 +120,24 @@ void S_Startup(void) void S_Shutdown(void) { + sfx_t *sfx; + int i; + Con_DPrintf("[FMOD] Shutdown\n"); S_StopAllSounds(true); - // TODO: destroy all FMOD_SOUNDs that are attached to sfx_t's + // Release all sounds that were loaded and attached to sfx_t's + for (i = 0; i < num_sfx; i++) + { + sfx = &known_sfx[i]; + + if (sfx->sound) + { + FMOD_Sound_Release(sfx->sound); + sfx->sound = NULL; + } + } // If we created the FMOD System (and consequently own it), destroy it here if (fmod_ownership)