在MKMapView上进行覆盖缩放时发生异常:NSInvalidArgumentException NSSetM removeObject:对象不能为nil [英] Exception when zooming with overlays on MKMapView: NSInvalidArgumentException NSSetM removeObject: object cannot be nil

查看:102
本文介绍了在MKMapView上进行覆盖缩放时发生异常:NSInvalidArgumentException NSSetM removeObject:对象不能为nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在MKMapView上添加大约1000个MKPolygon. 将叠加层添加到MKMapView后,它可以正常工作.但是,如果我放大并迅速缩小(有时放开变焦,以便mapView处理它是新的visibleMapRect),我发现该应用程序有时崩溃,并带有以下异常堆栈跟踪:

I am adding around 1000 MKPolygons onto an MKMapView. After adding the overlays onto the MKMapView it works fine. However if I zoom in and zoom out quickly (occasionally letting go of the zoom so the mapView processes it's new visibleMapRect) I find the app (sometimes) crashes with the following exception stack trace:

*** 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

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

This doesn't always happen. Often it's quite rare. You can see that it's hard to debug and work out what's going wrong because my project doesn't appear in the stack trace (except that it's running in my application...).

当试图找出问题时,我创建了一个非常基本的应用程序,只剩下一个MKMapView和1000个随机MKPolygons,每个随机生成了5个CLLocationCoordinate2D. 我发现该应用程序在缩放,静止,缩放,静止等情况下仍然崩溃. 我在这里所做的只是将基本随机MKPolygon添加到MKMapView中! 请注意,每个MKPolygonMKPolygonRenderer除了为其随机提供fillColor外,什么也没有做.

When trying to track down the issue I created a very basic app with nothing but an MKMapView and 1000 random MKPolygons with 5 randomly generated CLLocationCoordinate2D each. I found that the app still crashes when zooming, resting, zooming, resting, etc. But less likely? All I am doing here is adding basic random MKPolygons to the MKMapView! Note the MKPolygonRenderer for each MKPolygon does nothing apart from give it a random fillColor.

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

Note: I am running the application in Xcode on an iPhone 7 Simulator.

这是怎么回事? 谢谢!

What's going wrong here? Thanks!

推荐答案

添加&删除地图视图的注释.

I had a very similar problem when adding & removing annotations to a map view.

答案是将访问注解的所有内容(甚至是仅读取注解数组的计算)放到主线程上.

The answer turned out to be put everything that accesses the annotations - even calculations that only read the annotations array - onto the main thread.

我只输入了实际的&删除主线程,这在大多数情况下还可以,但是会随

I had only put the actual adding & removing on the main thread and it was ok for the most part, but would randomly crash with

[__ NSSetM removeObject:]:对象不能为空

[__NSSetM removeObject:]: object cannot be nil

这篇关于在MKMapView上进行覆盖缩放时发生异常:NSInvalidArgumentException NSSetM removeObject:对象不能为nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆