Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background thread issue leading to a crash #129

Open
letko-dmitry opened this issue May 5, 2020 · 4 comments
Open

Background thread issue leading to a crash #129

letko-dmitry opened this issue May 5, 2020 · 4 comments

Comments

@letko-dmitry
Copy link

(annotation as? MKPointAnnotation)?.coordinate = annotation.coordinate.coordinate(onBearingInRadians: bearing, atDistanceInMeters: self.distanceFromContestedLocation)

The line of code above triggers UI update via KVO on background thread and it leads to a crash because of precondition.

NSInternalInconsistencyException Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
0  CoreFoundation           __exceptionPreprocess + 220
1  libobjc.A.dylib          objc_exception_throw + 56
2  Foundation               -[NSISEngine tryToOptimizeReturningMutuallyExclusiveConstraints] + 0
3  Foundation               -[NSISEngine withBehaviors:performModifications:] + 32
4  UIKitCore                -[UIView(Hierarchy) _postMovedFromSuperview:] + 776
5  UIKitCore                -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1600
6  MapKit                   -[MKAnnotationContainerView addAnnotationView:allowAnimation:] + 1444
7  MapKit                   -[MKMapView addAnnotationRepresentation:allowAnimation:] + 588
8  MapKit                   -[MKAnnotationManager _addRepresentationForAnnotation:] + 668
9  MapKit                   -[MKAnnotationManager updateVisibleAnnotations] + 1008
10 MapKit                   -[MKAnnotationManager observeValueForKeyPath:ofObject:change:context:] + 996
11 Foundation               NSKeyValueNotifyObserver + 288
12 Foundation               NSKeyValueDidChange.llvm.18207776532572868477 + 332
13 Foundation               NSKeyValueDidChangeWithPerThreadPendingNotifications.llvm.18207776532572868477 + 148
14 Foundation               NSKVOForwardInvocation + 336
15 CoreFoundation           ___forwarding___ + 676
16 CoreFoundation           _CF_forwarding_prep_0 + 92
17 My App                   closure #3 in ClusterManager.distributeAnnotations(tree:mapRect:) + 824 (Cluster.swift)
@efremidze
Copy link
Owner

I don't see any preconditions in the framework that could cause this. This is probably a MapKit exception.

@letko-dmitry
Copy link
Author

Em, yes, exactly. And it forces us to set coordinate of an annotation on the main thread.

@crgt5252
Copy link

crgt5252 commented Jan 4, 2022

I'm seeing this crash in our app as well. Any workarounds?

@webcpu
Copy link

webcpu commented May 12, 2023

DispatchQueue.main.async {
   self.clusterManager.reload(self.mapView)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants