From 545057436c9c987332d0c292e569d404efa1153c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Wed, 10 Dec 2025 16:31:04 +0800 Subject: [PATCH 1/3] fix: ios view registration race condition --- .../GoogleMapsNavigationView.swift | 3 ++- .../GoogleMapsNavigationViewRegistry.swift | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift index f49b5323..75c2b407 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift @@ -133,7 +133,8 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle _viewRegistry.unregisterCarPlayView() } else { if let _viewId { - _viewRegistry.unregisterView(viewId: _viewId) + let viewInstanceId = ObjectIdentifier(self) + _viewRegistry.unregisterView(viewId: _viewId, viewIdToUnregister: viewInstanceId) } } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift index d1c7bb82..f48a937d 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift @@ -33,16 +33,14 @@ class GoogleMapsNavigationViewRegistry { ) func registerView(viewId: Int64, view: GoogleMapsNavigationView) { - queue.async(flags: .barrier) { [weak self] in - DispatchQueue.main.async { - self?.views[viewId] = view - } + queue.sync(flags: .barrier) { [weak self] in + self?.views[viewId] = view } } - func unregisterView(viewId: Int64) { + func unregisterView(viewId: Int64, viewIdToUnregister: ObjectIdentifier) { queue.async(flags: .barrier) { [weak self] in - DispatchQueue.main.async { + if let registeredView = self?.views[viewId], ObjectIdentifier(registeredView) == viewIdToUnregister { self?.views.removeValue(forKey: viewId) } } From c37d746f1b93849bdba43f2ddbf3cc224ff3c582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Thu, 11 Dec 2025 06:44:17 +0800 Subject: [PATCH 2/3] Update ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift Co-authored-by: Joonas Kerttula --- .../GoogleMapsNavigationViewRegistry.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift index f48a937d..ee50c1fa 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift @@ -38,7 +38,7 @@ class GoogleMapsNavigationViewRegistry { } } - func unregisterView(viewId: Int64, viewIdToUnregister: ObjectIdentifier) { + func unregisterView(viewId: Int64, viewInstanceIdToUnregister: ObjectIdentifier) { queue.async(flags: .barrier) { [weak self] in if let registeredView = self?.views[viewId], ObjectIdentifier(registeredView) == viewIdToUnregister { self?.views.removeValue(forKey: viewId) From 8ff82dc5fdb5dfa1df6b0a9c9f726f4e8bec485e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20V=C3=A4limaa?= Date: Thu, 11 Dec 2025 06:47:00 +0800 Subject: [PATCH 3/3] refactor: ios variable name changing --- .../google_navigation_flutter/GoogleMapsNavigationView.swift | 2 +- .../GoogleMapsNavigationViewRegistry.swift | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift index 75c2b407..eabac9ae 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationView.swift @@ -134,7 +134,7 @@ public class GoogleMapsNavigationView: NSObject, FlutterPlatformView, ViewSettle } else { if let _viewId { let viewInstanceId = ObjectIdentifier(self) - _viewRegistry.unregisterView(viewId: _viewId, viewIdToUnregister: viewInstanceId) + _viewRegistry.unregisterView(viewId: _viewId, viewInstanceIdToUnregister: viewInstanceId) } } } diff --git a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift index ee50c1fa..153615fd 100644 --- a/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift +++ b/ios/google_navigation_flutter/Sources/google_navigation_flutter/GoogleMapsNavigationViewRegistry.swift @@ -40,7 +40,9 @@ class GoogleMapsNavigationViewRegistry { func unregisterView(viewId: Int64, viewInstanceIdToUnregister: ObjectIdentifier) { queue.async(flags: .barrier) { [weak self] in - if let registeredView = self?.views[viewId], ObjectIdentifier(registeredView) == viewIdToUnregister { + if let registeredView = self?.views[viewId], + ObjectIdentifier(registeredView) == viewInstanceIdToUnregister + { self?.views.removeValue(forKey: viewId) } }