From 0cef35c34576302000a4278696426b0814e5840e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 19 Oct 2022 00:02:36 +0200 Subject: [PATCH] - SW: when an actor is killed, all attached ambient sounds must be deleted. Not only did the sound not stop but what happened here was very much undefined behavior as the ambient sound retained its pointer to now undefined memory. --- source/games/sw/src/sounds.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/games/sw/src/sounds.cpp b/source/games/sw/src/sounds.cpp index 33c0c21a5..3e6dca624 100644 --- a/source/games/sw/src/sounds.cpp +++ b/source/games/sw/src/sounds.cpp @@ -733,6 +733,17 @@ void DeleteNoSoundOwner(DSWActor* actor) } return false; }); + + // also delete all ambients attached to this actor. + for (int i = ambients.Size() - 1; i >= 0; i--) + { + auto amb = ambients[i]; + if (amb->spot == actor) + { + soundEngine->StopSound(SOURCE_Ambient, amb, -1); + ambients.Delete(i); + } + } } //==========================================================================