Sounds playing or stopped just before quitting leak their AudioStreamPlayback at exit

Aperta
#1,546 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Read AudioServer::playback_list and AudioServer::finish(), then trace shutdown ordering in Main::cleanup() to understand when playback classes are still available. Reproduce with the provided MRP using the Dummy driver and a run that quits while audio is playing. Done means shutdown frees the remaining playbacks and the reported leak no longer occurs; the issue describes an available fix and unit test, so review that change for the expected test location.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug topic:audio
Tested versions
  • Reproducible in: v26.3.stable.official [85e520394]
  • Also reproducible in an unmodified local build of the same commit.
  • Upstream Godot master has the same code, so it is probably affected too. I have not tested it.
System information

Windows 10 Pro 22H2 (build 19045), x86-64. Reproduced headless with the Dummy audio driver, and with WASAPI with the Master bus muted. The GPU and renderer are not involved.

Issue description

If a sound is still playing when the game quits, the engine prints:

WARNING: ObjectDB instances leaked at exit (run with --verbose for details).

The leaked objects are the AudioStreamPlayback and its AudioStream. With a local patch to list them, they were an AudioStreamPlaybackWAV and an AudioStreamWAV. A plain --verbose run lists nothing on 26.3, because ObjectDB::cleanup() skips some blocks when it lists leaks; that is a separate problem.

When it happens. In ordinary situations:

  • quitting with get_tree().quit() while music is playing;
  • calling stop() on a player in the same frame as quitting;
  • every bounded --quit-after run that ends while a sound plays. A script cannot stop its sounds first in that case, because the engine ends the main loop directly.

Workaround. Games have to stop every player and wait a few frames (about 0.25 s) before quitting.

Cause. A playback leaves AudioServer::playback_list in two steps:

  1. the audio thread marks it for deletion after its fade-out;
  2. AudioServer::update() frees it on the main thread.

At shutdown, neither step may run again, and nothing else empties the list. AudioServer::finish() only stops the drivers and deletes the buses. The SafeList destructor frees nodes that were already erased, but not nodes that are still in the list. With a real driver, the "stop then quit" case usually escapes, because the audio thread manages one more mix in time. With the Dummy driver it leaks every time.

Fix available. dominicbytes/redot-engine#9 (single commit b8fc04d, against 26.3-stable):

  • adds AudioServer::free_playbacks(), which frees every playback left in the list with the audio driver locked;
  • calls it from Main::cleanup() right after the script languages finish, before the modules and GDExtensions that provide playback classes are uninitialized;
  • adds a unit test.
Ending Official 26.3-stable With the fix
Still playing, run ends by --quit-after 60 5 of 5 runs leak 0 of 20
Still playing, get_tree().quit() 5 of 5 0 of 20
stop() then get_tree().quit() in the same frame 5 of 5 0 of 20
stop(), wait 0.25 s, then quit 0 of 5 0 of 10

The full unit-test suite passes with the fix, 1347 of 1347.

Steps to reproduce
  1. Create the MRP below.
  2. Import it once: redot --headless --path <mrp> --import.
  3. Run any of these and look for the ObjectDB warning at exit:
    • redot --headless --audio-driver Dummy --path <mrp> --quit-after 60 -- --mode=play
    • redot --headless --audio-driver Dummy --path <mrp> -- --mode=play-quit
    • redot --headless --audio-driver Dummy --path <mrp> -- --mode=stop-quit
  4. As a control, -- --mode=stop-wait exits cleanly.

To hear nothing with a real driver, use --audio-driver WASAPI and add --mute after --.

Minimal reproduction project (MRP)

Bugsquad edit:

audio-playback-shutdown-leak-mrp.zip


Lingua principale
C++
Stelle
6.1k
Fork
337
Merge medio
5g 8h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Redot-Engine/redot-engine

Tutte le issue di Redot-Engine/redot-engine

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.