I'm displaying a MKMapView in SwiftUI by wrapping it in the UIViewRepresentable protocol.
I think the crash may have something to do with "Metal API Validation Enabled"
I'm running Xcode Version 13.1 (13A1030d)
My iPhone is iOS 15.1
When I run the app, the map displays and if I rotate my phone the Map rotates properly. BUT after two or three rotations the app crashes. The top of the stack trace says:
queue = 'com.Metal.CompletionQueueDispatch', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
The Error displayed is "Thread 12: EXC_BAD_ACCESS (code=1, address=0x10)"
I've reduced the code to just a few lines shown below
ContentView.swift:
struct ContentView: View {
var body: some View {
MapView()
}
}
MapView.swift:
struct MapView: UIViewRepresentable {
typealias UIViewType = MKMapView
// Required by UIViewRepresentable protocol
func makeUIView(context: Context) -> MKMapView {
return MKMapView()
}
// Required by UIViewRepresentable protocol
func updateUIView(_ mapView: MKMapView, context: Context) {
print("updateUIView() called")
}
}
After the Console output shown below is displayed I rotate the phone back and forth several times to get the map to rotate between portrait and landscape. After several rotations I get the crash. The Console Output before the crash is is shown below.
2021-12-07 15:24:00.879362-0700 UIViewRepresentableHelloWorld[26817:1293647] Metal API Validation Enabled updateUIView() called
The Stack Trace is shown below:
* thread #18, queue = 'com.Metal.CompletionQueueDispatch', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
* frame #0: 0x0000000197a3a014 libobjc.A.dylib`objc_msgSend + 20
frame #1: 0x00000001cc5809a4 MetalTools`-[MTLDebugCommandBuffer preCompletionHandlers] + 316
frame #2: 0x00000001cc536070 MetalTools`-[MTLToolsCommandBuffer invokeCompletedHandlers] + 36
frame #3: 0x000000019958efa0 Metal`MTLDispatchListApply + 44
frame #4: 0x000000019958f374 Metal`-[_MTLCommandBuffer didCompleteWithStartTime:endTime:error:] + 596
frame #5: 0x00000001cb3fe144 IOGPU`-[IOGPUMetalCommandBuffer didCompleteWithStartTime:endTime:error:] + 216
frame #6: 0x000000019958f04c Metal`-[_MTLCommandQueue commandBufferDidComplete:startTime:completionTime:error:] + 132
frame #7: 0x00000001cb3fdf04 IOGPU`__IOGPUNotificationQueueSetDispatchQueue_block_invoke + 148
frame #8: 0x000000010486a048 libdispatch.dylib`_dispatch_client_callout4 + 16
frame #9: 0x0000000104885364 libdispatch.dylib`_dispatch_mach_msg_invoke + 424
frame #10: 0x0000000104870ff0 libdispatch.dylib`_dispatch_lane_serial_drain + 332
frame #11: 0x0000000104886188 libdispatch.dylib`_dispatch_mach_invoke + 504
frame #12: 0x0000000104870ff0 libdispatch.dylib`_dispatch_lane_serial_drain + 332
frame #13: 0x0000000104871e08 libdispatch.dylib`_dispatch_lane_invoke + 484
frame #14: 0x0000000104870ff0 libdispatch.dylib`_dispatch_lane_serial_drain + 332
frame #15: 0x0000000104871dd4 libdispatch.dylib`_dispatch_lane_invoke + 432
frame #16: 0x000000010487d4e8 libdispatch.dylib`_dispatch_workloop_worker_thread + 852
frame #17: 0x00000001da86de84 libsystem_pthread.dylib`_pthread_wqthread + 284