From 2cf57a3eb71486562c902bd45f880262d3807894 Mon Sep 17 00:00:00 2001 From: Thomas Martin Date: Fri, 27 Nov 2026 02:25:34 +0100 Subject: [PATCH] 989SND: a bank's unload stops its sounds still playing The native driver retired an unloaded bank but left the handlers playing its sounds running. The driver stops them first (OpenGOAL's 989snd, after the same library, frees the bank's handlers in unload_bank). TMB showed it: quitting a match from the pause unloads the level's banks without a StopAllSounds, and the match's music, played from its bank, went on over the menus. Engine::bankUnloaded now stops the bank's handlers at once (stopHandler, as StopAllSounds does) before freeing its SPU memory and retiring it. Co-Authored-By: Claude Opus 5.5 --- runtime/libs/snd989.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/libs/snd989.cpp b/runtime/libs/snd989.cpp index 0bc8e86..a432f58 100644 --- a/runtime/libs/snd989.cpp +++ b/runtime/libs/snd989.cpp @@ -2853,9 +2853,19 @@ namespace bozo::libs::snd989 for (auto it = I.banks.begin(); it != I.banks.end(); ++it) if ((*it)->address == address) { + Impl::Bank *b = it->get(); + // The bank's sounds still playing stop first, at once (as StopAllSounds stops each): the driver's + // unload does, and a match's music, played from its bank, otherwise went on over the menus after the + // match was quit (TMB: the level's banks unloaded on leaving, no StopAllSounds sent). + for (Impl::Handler *h = I.hHead; h;) + { + Impl::Handler *next = h->next; + if (h->bank == b) + I.stopHandler(h, true); + h = next; + } if ((*it)->spu) I.spuFree((*it)->spu, (*it)->spuBytes); - Impl::Bank *b = it->get(); std::erase_if(I.blocks, [&](const Impl::Block &k) { return k.owner == b; }); I.retired.push_back(std::move(*it)); I.banks.erase(it);