I'm having trouble finding a bug in my app because it only presents itself after an adhoc installation. I have narrowed it down to [self.mapview removeOverlay:overlay];
and '[self.mapview addOverlay:overlay]. The exact same code with the exact same steps works just minutes before if I install and debug via Xcode (4.6.1). I'm not changing any other settings in between tests. I just Archive and distribute the app, or I press the Run button and it gets pushed to my iPad. One time it works, one time it fails.
Xcode->device = overlays can come and go as I want Xcode->adhoc->server->device = complete app freeze when I try to remove a visible overlay or add one that is within the area the map can see right now
I've looked at the crash logs on the device and it always within [MKOverlayClusterView didAddSubview:] or [MKOverlayClusterView willRemoveSubview:]
Here's the main thread as shown in the crash log
0 libsystem_kernel.dylib 0x3c4ff27c __psynch_rw_wrlock + 24
1 libsystem_c.dylib 0x3c44fbd6 pthread_rwlock_wrlock + 334
2 MapKit 0x34fb321e -[MKOverlayClusterView willRemoveSubview:] + 50
3 UIKit 0x3614b2d2 __UIViewWillBeRemovedFromSuperview + 126
4 UIKit 0x35f93844 -[UIView(Hierarchy) removeFromSuperview] + 52
5 MapKit 0x34fae5b0 -[MKOverlayContainerView _removeOverlayView:forOverlay:coalesce:] + 24
6 MapKit 0x34fae118 -[MKOverlayContainerView removeOverlays:] + 240
It's worth noting that in both the add/remove variants the last top of the stack is the same so perhaps this is an issue with pthread_rwlock_wrlock meaning I've crossed threads at some point. I have tried to protect against this by using [self performSelectorOnMainThread:@selector(mainThreadRemoveOverlays:) withObject:@[overlay] waitUntilDone:YES]; but the crash keeps happening when the app is installed via the adhoc method and never happens when debugging via Xcode.