feat: Implement audio shutdown procedure for graceful app exit
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -26,6 +26,8 @@ class Wolf3d {
|
||||
/// Shared engine audio backend used by menus and gameplay sessions.
|
||||
final EngineAudio audio;
|
||||
|
||||
Future<void>? _audioShutdownFuture;
|
||||
|
||||
/// Engine menu background color as 24-bit RGB.
|
||||
int menuBackgroundRgb = 0x890000;
|
||||
|
||||
@@ -246,6 +248,24 @@ class Wolf3d {
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Stops and disposes shared audio exactly once for app shutdown.
|
||||
///
|
||||
/// Repeated calls return the same in-flight/completed future so hosts can
|
||||
/// safely invoke shutdown from multiple lifecycle paths.
|
||||
Future<void> shutdownAudio() {
|
||||
final existing = _audioShutdownFuture;
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
final shutdown = () async {
|
||||
await audio.stopAllAudio();
|
||||
audio.dispose();
|
||||
}();
|
||||
_audioShutdownFuture = shutdown;
|
||||
return shutdown;
|
||||
}
|
||||
|
||||
/// Loads an asset from the Flutter bundle, returning `null` when absent.
|
||||
Future<ByteData?> _tryLoad(String path) async {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user