ios - 在 MKMapView : NSInvalidArgumentException NSSetM removeObject: object cannot be nil 上使用叠加层缩放时出现异常

标签 ios objective-c xcode mapkit overlays

我将大约 1000 个 MKPolygon 添加到 MKMapView 上。 将叠加层添加到 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

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

在尝试追踪问题时,我创建了一个非常基本的应用程序,其中只有一个 MKMapView 和 1000 个随机 MKPolygons 以及 5 个随机生成的 CLLocationCoordinate2D 每个。 我发现应用程序在缩放、静止、缩放、静止等时仍然会崩溃。但不太可能? 我在这里所做的就是将基本的随机 MKPolygon 添加到 MKMapView! 注意每个 MKPolygonMKPolygonRenderer 除了给它一个随机的 fillColor 之外什么都不做。

注意:我在 iPhone 7 模拟器上的 Xcode 中运行该应用程序。

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

最佳答案

我在向 map View 添加和删除注释时遇到了非常相似的问题。

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

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

[__NSSetM removeObject:]: object cannot be nil

关于ios - 在 MKMapView : NSInvalidArgumentException NSSetM removeObject: object cannot be nil 上使用叠加层缩放时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45732344/

相关文章:

ios - Amazon SNS 移动推送 - 如何批量订阅一个主题的端点?

ios - UIButton - 触摸更改图像

ios - 尝试在单击按钮但不触发方法时显示 ViewController 时出错

objective-c - 从 iOS Objective-C 上传数据到网站

iphone - NavigationController背景图像问题

ios - 每两次点击按钮时显示一次全屏广告

ios - Swift Socket.io连接后立即发送的事件未执行

ios - Altas 层创建假的初始消息

iphone - Storyboard 应用程序也可以在 iOS 5 之前的设备上运行吗?

ios - swift 2.0 : Delegate is not working