From 13ac657ebfb4ab4ef5850b802d75a03b447d8bf0 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 12 Apr 2021 18:55:52 +0200 Subject: [PATCH] Make deleting listenerSlot in idSoundWorldLocal::Shutdown() work the problem was that the sources were still associated to it, because they get deleted after the listenerSlot: the sources get freed in idSoundSystemLocal::Shutdown() which is called by idCommonLocal::ShutdownGame() in line 3217, while the listenerSlot is deleted via idSessionLocal::Shutdown() -> delete sw/rw -> idSoundWorldLocal::~idSoundWorldLocal() -> idSoundWorldLocal::Shutdown() - and idSessionLocal::Shutdown() is called in idCommonLocal::ShutdownGame() line 3211, before the other. I'm not gonna mess with the order of deleting things in ShutdownGame(), but it's sufficient to unassociate the effect slot from the source when destroying the emitters in idSoundWorldLocal::Shutdown(), by adding a call for that to idSoundChannel::ALStop() - and destroying the emitters before deleting listenerSlot. Before this fix, with ALSOFT_LOGLEVEL=3 you got the following warning: (WW) Error generated on context 0x5578fce2a280, code 0xa004, "Deleting in-use effect slot 1" Thanks for openal-soft's KittyCat for pointing this out! --- neo/sound/snd_emitter.cpp | 3 +++ neo/sound/snd_world.cpp | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/neo/sound/snd_emitter.cpp b/neo/sound/snd_emitter.cpp index 08c6fa38..495da4d1 100644 --- a/neo/sound/snd_emitter.cpp +++ b/neo/sound/snd_emitter.cpp @@ -227,6 +227,9 @@ void idSoundChannel::ALStop( void ) { if ( alIsSource( openalSource ) ) { alSourceStop( openalSource ); alSourcei( openalSource, AL_BUFFER, 0 ); + // unassociate effect slot from source, so the effect slot can be deleted on shutdown + // even though the source itself is deleted later (in idSoundSystemLocal::Shutdown()) + alSource3i( openalSource, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL ); soundSystemLocal.FreeOpenALSource( openalSource ); } diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index 5247701e..20270c27 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -157,6 +157,15 @@ void idSoundWorldLocal::Shutdown() { AVIClose(); + // delete emitters before deletign the listenerSlot, so their sources aren't + // associated with the listenerSlot anymore + for ( i = 0; i < emitters.Num(); i++ ) { + if ( emitters[i] ) { + delete emitters[i]; + emitters[i] = NULL; + } + } + if (idSoundSystemLocal::useEFXReverb) { if (soundSystemLocal.alIsAuxiliaryEffectSlot(listenerSlot)) { soundSystemLocal.alAuxiliaryEffectSloti(listenerSlot, AL_EFFECTSLOT_EFFECT, AL_EFFECTSLOT_NULL); @@ -175,12 +184,6 @@ void idSoundWorldLocal::Shutdown() { } } - for ( i = 0; i < emitters.Num(); i++ ) { - if ( emitters[i] ) { - delete emitters[i]; - emitters[i] = NULL; - } - } localSound = NULL; }