Skip to content

Background thread issue leading to a crash #129

@letko-dmitry

Description

@letko-dmitry

(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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions