MKMapView produces error Tracking renderables for inactive registry

  Kiến thức lập trình

In my iOS app in order to switch between normal and satellite view on a map and because SwiftUI’s Map does not support map type on iOS 16 (support is required), I am wrapping MKMapView in a UIViewRepresentable and integrate it in a normal SwiftUI View.

import Foundation
import MapKit
import SwiftUI

struct MapView: UIViewRepresentable {
    @Binding var region: MKCoordinateRegion
    @Binding var showSatelliteView: Bool
    @Binding var followUser: Bool

    func makeUIView(context: Context) -> MKMapView {
        let mkMapView = MKMapView(frame: .zero)
        mkMapView.delegate = context.coordinator
        updateMKMapView(mkMapView)
        return mkMapView
    }

    func updateUIView(_ mkMapView: MKMapView, context: Context) {
        updateMKMapView(mkMapView)
    }

    fileprivate func updateMKMapView(_ mkMapView: MKMapView) {
        mkMapView.setRegion(region, animated: true)
        mkMapView.preferredConfiguration = showSatelliteView ? MKImageryMapConfiguration() : MKStandardMapConfiguration()
        mkMapView.userTrackingMode = followUser ? .follow : .none
    }
        
    // MARK: Coordinator
    
    final class Coordinator: NSObject, MKMapViewDelegate {
     
        var parent: MapView
     
        init(_ parent: MapView) {
            self.parent = parent
        }
     
        func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
            parent.region = mapView.region
        }
        
        func mapView(
            _ mapView: MKMapView,
            didChange mode: MKUserTrackingMode,
            animated: Bool
        ) {
            parent.followUser = mapView.userTrackingMode == .follow || mapView.userTrackingMode == .followWithHeading
        }
    }
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
}

showSatelliteView is initially set to false. I then change it to true and then back to false from a bound toggle button in the hosting View. As this last change happens on those devices

  • iOS 16.7.4 (physical iPad Pro 9.7″)
  • iOS 16.4 (simulator iPad mini 6th gen)

I get following error

[RegistryManager] Tracking a LayerData with no associated Registry: Assertion with expression - layerDataSets.keys.exiting.empty() : Failed in file - /Library/Caches/com.apple.xbs/Sources/VectorKit/src/RegistryManager.mm line - 473

Followed by repeated

[MeshRenderableLogic] Tracking renderables for inactive registry    
[MeshRenderableLogic] Tracking renderables for inactive registry
... (140+)

until it crashes with signal SIGABRT

The same errors are produced on iPhone 15 Pro Simulator iOS 17.0.1 and 17.2 but without crashing.

Do you have a clue about what is causing the crash?

LEAVE A COMMENT