Skip to content

Commit f8f1932

Browse files
committed
Fix race condition
1 parent 2d682dc commit f8f1932

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Diff for: Sources/MapboxNavigation/CPInterfaceController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public extension CPInterfaceController {
1212
animated or not.
1313
*/
1414
func safePopTemplate(animated: Bool) {
15-
if templates.count >= 1 { return }
16-
15+
guard templates.count > 1 else { return }
16+
1717
popTemplate(animated: animated)
1818
}
1919
}

Diff for: Sources/MapboxNavigation/CarPlayManager.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public class CarPlayManager: NSObject {
102102
private weak var navigationService: NavigationService?
103103
private var idleTimerCancellable: IdleTimerManager.Cancellable?
104104
private var indexedRouteResponse: IndexedRouteResponse?
105-
105+
private let semaphore = DispatchSemaphore(value: 1)
106+
106107
/**
107108
Programatically begins a CarPlay turn-by-turn navigation session.
108109

@@ -653,6 +654,9 @@ extension CarPlayManager {
653654
}
654655

655656
func previewRoutes(for trip: CPTrip) {
657+
semaphore.wait()
658+
defer { semaphore.signal() }
659+
656660
guard let traitCollection = (self.carWindow?.rootViewController as? CarPlayMapViewController)?.traitCollection,
657661
let interfaceController = interfaceController else {
658662
return

0 commit comments

Comments
 (0)