我添加了大约1000MKPolygon
到一个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
!
请注意MKPolygonRenderer
对于每个MKPolygon
除了随机赋予它之外什么也不做fillColor
.
注意:我正在 iPhone 7 模拟器上的 Xcode 中运行该应用程序。
这里出了什么问题?
谢谢!
在向地图视图添加和删除注释时,我遇到了非常类似的问题。
答案是将所有访问注释的东西——甚至是只读取注释数组的计算——放到主线程上。
我只将实际的添加和删除放在主线程上,大部分情况下都可以,但会随机崩溃
[__NSSetM removeObject:]: 对象不能为 nil
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)