MKMapSnapshotter/VectorKit crash since iOS 16

We "recently" started getting crashes when taking a satelite map snapshot in app using MKMapSnapshotter. We realized that all crashes have a common denominator that they all happened on iOS 16.

The code that creates the snapshot has been unaltered and working without crashes since 2018 up until the release of iOS 16. This is likely some bug in the SDK.

let options = MKMapSnapshotter.Options()
        let location = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)

        options.mapType = .satelliteFlyover
        options.size = size
        options.camera = MKMapCamera(lookingAtCenter: location, fromDistance: distance, pitch: 0, heading: 0)

        let snapshotter = MKMapSnapshotter(options: options)
        snapshotter.start(completionHandler: completionHandler)
Crashed: com.apple.maps.snapshotter
0  VectorKit                      0x95d8f0 ggl::Renderer::removeDebugRenderer(std::__1::shared_ptr<ggl::DebugRenderer> const&) + 40
1  VectorKit                      0x5cc588 md::DebugConsoleManager::~DebugConsoleManager() + 120
2  VectorKit                      0x5cc588 md::DebugConsoleManager::~DebugConsoleManager() + 120
3  VectorKit                      0x14e4f4 std::__1::unique_ptr<md::DebugConsoleManager, std::__1::default_delete<md::DebugConsoleManager> >::reset(md::DebugConsoleManager*) + 32
4  VectorKit                      0x1b4a48 -[GGLImageCanvas .cxx_destruct] + 36
5  libobjc.A.dylib                0x14a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
6  libobjc.A.dylib                0x621c objc_destructInstance + 80
7  libobjc.A.dylib                0xf9d0 _objc_rootDealloc + 80
8  VectorKit                      0x145958 -[GGLImageCanvas dealloc] + 44
9  VectorKit                      0x6eacc md::MapEngine::~MapEngine() + 1644
10 VectorKit                      0x133e6c md::MapEngine::~MapEngine() + 16
11 VectorKit                      0x33b30 -[VKMapSnapshotCreator softDealloc] + 352
12 VectorKit                      0x33778 __42-[VKMapSnapshotCreator renderNextSnapshot]_block_invoke + 904
13 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release + 32
14 libdispatch.dylib              0x3fdc _dispatch_client_callout + 20
15 libdispatch.dylib              0xb694 _dispatch_lane_serial_drain + 672
16 libdispatch.dylib              0xc214 _dispatch_lane_invoke + 436
17 libdispatch.dylib              0x16e10 _dispatch_workloop_worker_thread + 652
18 libsystem_pthread.dylib        0xdf8 _pthread_wqthread + 288
19 libsystem_pthread.dylib        0xb98 start_wqthread + 8

Ofcourse i could be mistaken, any input to what could otherwise be the cause is greatly appreciated

I have the same problem. This is my debug output: -[MTLDebugDevice notifyExternalReferencesNonZeroOnDealloc:]:2885: failed assertion `The following Metal object is being destroyed while still required to be alive by the command buffer 0x3260f3800 (label: ): <MTLToolsObject: 0x600000d08360> -> <IOGPUMetalFence: 0x600000d0bc60>'

[MTLDebugDevice notifyExternalReferencesNonZeroOnDealloc:]:2885: failed assertion The following Metal object is being destroyed while still required to be alive by the command buffer 0x14b26c200 (label: <no label set>):

Has random crash in SwifUI view which is hosting by UIHostingController

how is notifyExternalReferencesNonZeroOnDealloc related to the MKMapSnapshotter bug?

Did you ever get a resolution or more info for this? I'm facing the same issue and have also only seen it on iOS 16 so far.

I've seen several memory related error messages accompanying the crashes:

  1. malloc: Incorrect checksum for freed object 0x1271ce1c8: probably modified after being freed. Corrupt value: 0x3f58fec800000000
  2. malloc: tiny_free_list_remove_ptr: Internal invariant broken (prev ptr of next): ptr=0x1574c3f10, next_prev=0x30000022c447191
  3. malloc: Corruption at 0x108dd3c30: unexpected msizes 0&#x2F;43
  4. malloc: tiny_free_list_remove_ptr: Internal invariant broken (prev ptr of next): ptr=0x14c891e90, next_prev=0x0
  5. malloc: Corruption of free object 0x14d369fc0: msizes 14424&#x2F;0 disagree

No i created a bugreport to apple but haven't heard anything on the issue since reporting it unfortunately :(

It seems like you can work around this issue by disabling Metal API Validation checking in the Scheme Diagnostics window. I noticed that it wouldn't crash when I wasn't connected to the debugger, so I think this is an issue of Metal API sanity checking. Since it seems to throw the error from MapKit code, there's not much else we can do. (I ruled out concurrency problems by passing in the main queue, and also only calling it from the main actor--both of which continued to crash.) Once I disabled the Metal API Validation, I stopped getting crashes while hooked up to Xcode.

MKMapSnapshotter/VectorKit crash since iOS 16
 
 
Q