使用MKMapView上的叠加层进行缩放时出现异常:NSInvalidArgumentException NSSetM removeObject:object不能为零

Bec*_*hsh 7 xcode objective-c overlays mapkit ios

我正在添加大约1000 MKPolygonMKMapView.将叠加层添加到MKMapView其上后,它可以正常工作.但是,如果我快速放大并缩小(偶尔放开缩放以便mapView进程是新的visibleMapRect),我发现应用程序(有时)会崩溃并出现以下异常堆栈跟踪:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSSetM removeObject:]: object cannot be nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107db6b0b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010781b141 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107d1712a -[__NSSetM removeObject:] + 538
    3   VectorKit                           0x000000010bae84fa -[VKRasterOverlayTileSource removeOverlay:] + 89
    4   VectorKit                           0x000000010b79a648 -[VKMapModel removeRasterOverlay:] + 68
    5   MapKit                              0x0000000106f93bf1 -[MKOverlayContainerView _removeDrawable:forOverlay:level:] + 502
    6   MapKit                              0x0000000106f92633 -[MKOverlayContainerView addAndRemoveOverlayViews] + 785
    7   MapKit                              0x0000000106f44772 -[MKMapView _didChangeRegionMidstream:] + 229
    8   MapKit                              0x0000000106f49528 -[MKMapView mapLayer:didChangeRegionAnimated:] + 91
    9   VectorKit                           0x000000010b7d39e8 -[VKMapCameraController rotateToYaw:withPoint:animated:] + 884
    10  VectorKit                           0x000000010b7d4e7b -[VKMapCameraController snapMapIfNecessary:] + 389
    11  MapKit                              0x0000000106f93bf1 -[MKOverlayContainerView _removeDrawable:forOverlay:level:] + 502
    12  MapKit                              0x0000000106f92633 -[MKOverlayContainerView addAndRemoveOverlayViews] + 785
    13  MapKit                              0x0000000106f44772 -[MKMapView _didChangeRegionMidstream:] + 229
    14  MapKit                              0x0000000106f49528 -[MKMapView mapLayer:didChangeRegionAnimated:] + 91
    15  VectorKit                           0x000000010b9f7b0e -[VKScreenCameraController stopPinchingWithFocusPoint:] + 64
    16  MapKit                              0x0000000106fbb1e3 __38-[MKMapGestureController handlePinch:]_block_invoke.184 + 126
    17  VectorKit                           0x000000010b78aaa2 -[VKAnimation stopAnimation:] + 109
    18  VectorKit                           0x000000010b8f9a3d -[VKDynamicAnimation stopAnimation:] + 45
    19  MapKit                              0x0000000106fb7819 -[MKMapGestureController stopDynamicAnimations] + 50
    20  MapKit                              0x0000000106fba254 -[MKMapGestureController gestureRecognizerTouchesBegan:] + 39
    21  MapKit                              0x0000000106fbbab1 -[_MKUserInteractionGestureRecognizer touchesBegan:withEvent:] + 198
    22  UIKit                               0x0000000108e9b934 -[UIGestureRecognizer _touchesBegan:withEvent:] + 113
    23  UIKit                               0x0000000108e8901c __55-[UIGestureEnvironment _updateGesturesForEvent:window:]_block_invoke + 337
    24  UIKit                               0x0000000108e89b79 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 282
    25  UIKit                               0x0000000108e88e0a -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
    26  UIKit                               0x00000001089d4eea -[UIWindow sendEvent:] + 4092
    27  UIKit                               0x0000000108981a84 -[UIApplication sendEvent:] + 352
    28  UIKit                               0x00000001091655d4 __dispatchPreprocessedEventFromEventQueue + 2926
    29  UIKit                               0x000000010915d532 __handleEventQueue + 1122
    30  UIKit                               0x000000010915e800 __handleEventQueue + 5936
    31  CoreFoundation                      0x0000000107d5cc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    32  CoreFoundation                      0x0000000107d420cf __CFRunLoopDoSources0 + 527
    33  CoreFoundation                      0x0000000107d415ff __CFRunLoopRun + 911
    34  CoreFoundation                      0x0000000107d41016 CFRunLoopRunSpecific + 406
    35  GraphicsServices                    0x000000010cc97a24 GSEventRunModal + 62
    36  UIKit                               0x0000000108964134 UIApplicationMain + 159
    37  MyProject                                0x0000000106e51a9f main + 111
    38  libdyld.dylib                       0x000000010e56165d start + 1
Run Code Online (Sandbox Code Playgroud)

这并不总是发生.通常它很少见.您可以看到很难调试并解决出现问题的原因,因为我的项目没有出现在堆栈跟踪中(除了它在我的应用程序中运行...).

在尝试追踪问题的时候,我创建了一个非常基本的应用程序,只有MKMapView1000个随机MKPolygons,CLLocationCoordinate2D每个随机生成5个.我发现该应用程序在缩放,休息,缩放,休息等时仍然会崩溃.但不太可能?所有我在这里做的是将基本随机MKPolygon年代到MKMapView!注意除了给它一个随机的MKPolygonRenderer每个MKPolygon什么都没做fillColor.

注意:我在iPhone 7 Simulator上运行Xcode中的应用程序.

这里出了什么问题?谢谢!

Ugl*_*Cat 0

在向地图视图添加和删除注释时,我遇到了非常类似的问题。

答案是将所有访问注释的东西——甚至是只读取注释数组的计算——放到主线程上。

我只将实际的添加和删除放在主线程上,大部分情况下都可以,但会随机崩溃

[__NSSetM removeObject:]: 对象不能为 nil