From ce99352e90d0f0c60c19254da429437fd7083dbf Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 9 Jul 2024 23:27:18 -0700 Subject: [PATCH] Don't let let audio session tokens be double consumed --- Tusker/AudioSessionCoordinator.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tusker/AudioSessionCoordinator.swift b/Tusker/AudioSessionCoordinator.swift index f2cea65710..ef310613e6 100644 --- a/Tusker/AudioSessionCoordinator.swift +++ b/Tusker/AudioSessionCoordinator.swift @@ -34,6 +34,8 @@ final class AudioSessionCoordinator { } func endPlayback(token: Token, completionHandler: (() -> Void)? = nil) { + // mark the token as consumed, so when it's deinited we don't try to end again + token.consumed = true // the enqueued block can't retain token, since it may be being dealloc'd right now let mode = token.mode queue.async { @@ -70,13 +72,16 @@ final class AudioSessionCoordinator { final class Token { let mode: Mode + fileprivate var consumed = false init(mode: Mode) { self.mode = mode } deinit { - AudioSessionCoordinator.shared.endPlayback(token: self) + if !consumed { + AudioSessionCoordinator.shared.endPlayback(token: self) + } } }