MapKit: It's not safe to call MKMapView's addOverlay on a non-main-queue, even if it is executed on the main thread

Number:rdar://24025596 Date Originated:30-Dec-2015 02:15 PM
Status:Open Resolved:
Product:iOS SDK Product Version:9.2
Classification:Serious Bug Reproducible:Always
This crashes with EXC_BAD_ACCESS:

	let myqueue = dispatch_queue_create("myqueue", dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0))
	dispatch_sync(myqueue) {
	if NSThread.isMainThread() {
		mapView.addOverlay(polyline, level: .AboveRoads)
	} else {
		dispatch_async(dispatch_get_main_queue()) {
			mapView.addOverlay(polyline, level: .AboveRoads)
I’m attaching an iOS playground which demonstrates the issue.

Is this expected behavior? My understanding was, as long as UI related code is executed on the main thread, it is safe. This case lets me assume this is not always the case.

See on why this might be a problem


Crashed Thread:        0  Dispatch queue: myqueue

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Thread 0 Crashed:: Dispatch queue: myqueue
0   libdispatch.dylib             	0x0000000108256906 dispatch_retain + 0
1           	0x000000010b029353 -[VKRasterOverlayTileSource init] + 163
2           	0x000000010ac51451 -[VKMapModel _rasterOverlayTileSourceForLevel:] + 289
3           	0x000000010ac51bd4 -[VKMapModel addRasterOverlay:] + 52
4              	0x0000000105fd532f -[MKOverlayContainerView _insertDrawable:forOverlay:atIndex:level:] + 1365
5              	0x0000000105fd31a5 -[MKOverlayContainerView _configureAndAddDrawable:forOverlay:level:] + 401
6              	0x0000000105fd338e -[MKOverlayContainerView _considerAddingDrawable:inAddRect:level:] + 461
7              	0x0000000105fd3b6d -[MKOverlayContainerView addOverlay:level:] + 198
8              	0x0000000105fc6c94 -[MKMapView(OverlaysAPI) addOverlay:level:] + 85


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!