romaonthego / REMarkerClusterer

REMarkerClusterer creates and manages per-zoom-level clusters for large amounts of markers.
MIT License
195 stars 30 forks source link

Not working on iOS 9.1 / Xcode 7.1 #38

Open amsoell opened 9 years ago

amsoell commented 9 years ago

I've been trying to implement this in an app and running into errors, so I downloaded the example assuming it would show me my problem. Unfortunately the REMarkerClustererExample app throws the same error out of the box:

REMarkerClustererExample[12235:1101103] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000109be0f45 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010965adeb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000109b8f975 -[__NSArray0 objectAtIndex:] + 101
    3   REMarkerClustererExample            0x00000001076c0b20 -[REMarkerClusterer mapView:regionDidChangeAnimated:] + 208
    4   MapKit                              0x00000001077f0947 -[MKMapView _didChangeRegionMidstream:] + 791
    5   MapKit                              0x00000001077f535a -[MKMapView mapLayer:didChangeRegionAnimated:] + 81
    6   VectorKit                           0x000000010d2dd19c -[VKMapCameraController _animateToPosition:pitch:yaw:duration:timingCurve:completion:] + 4620
    7   VectorKit                           0x000000010d2dbf53 -[VKMapCameraController animateToMapRegion:pitch:yaw:duration:completion:] + 723
    8   MapKit                              0x00000001077fb7c4 -[MKMapView _goToMapRegion:duration:animated:completionHandler:] + 350
    9   MapKit                              0x00000001077fb553 -[MKMapView _setZoomScale:centerMapPoint:duration:animated:] + 598
    10  UIKit                               0x0000000107b64c10 +[UIView(Animation) performWithoutAnimation:] + 65
    11  MapKit                              0x00000001077fd161 -[MKMapView _goToCenterCoordinate:zoomLevel:animated:] + 993
    12  MapKit                              0x00000001077fab46 -[MKMapView setRegion:animated:] + 402
    13  REMarkerClustererExample            0x00000001076bc6aa -[REMarkerClusterer setMapRegionForMinLat:minLong:maxLat:maxLong:] + 522
    14  REMarkerClustererExample            0x00000001076bbe87 -[REMarkerClusterer zoomToAnnotationsBounds:] + 839
    15  REMarkerClustererExample            0x00000001076b75c4 -[DemoViewController viewDidLoad] + 2692
    16  UIKit                               0x0000000107c4dcc4 -[UIViewController loadViewIfRequired] + 1198
    17  UIKit                               0x0000000107c920ee -[UINavigationController _layoutViewController:] + 54
    18  UIKit                               0x0000000107c929c2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
    19  UIKit                               0x0000000107c92b34 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
    20  UIKit                               0x0000000107c93d8d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
    21  UIKit                               0x0000000107c94cea -[UINavigationController __viewWillLayoutSubviews] + 57
    22  UIKit                               0x0000000107e3ac85 -[UILayoutContainerView layoutSubviews] + 248
    23  UIKit                               0x0000000107b6fe40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
    24  QuartzCore                          0x000000010ddc959a -[CALayer layoutSublayers] + 146
    25  QuartzCore                          0x000000010ddbde70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    26  QuartzCore                          0x000000010ddbdcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    27  QuartzCore                          0x000000010ddb2475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
    28  QuartzCore                          0x000000010dddfc0a _ZN2CA11Transaction6commitEv + 486
    29  QuartzCore                          0x000000010dde037c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    30  CoreFoundation                      0x0000000109b0c947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    31  CoreFoundation                      0x0000000109b0c8b7 __CFRunLoopDoObservers + 391
    32  CoreFoundation                      0x0000000109b01e2c CFRunLoopRunSpecific + 524
    33  UIKit                               0x0000000107ab64f5 -[UIApplication _run] + 402
    34  UIKit                               0x0000000107abb30d UIApplicationMain + 171
    35  REMarkerClustererExample            0x00000001076b674f main + 111
    36  libdyld.dylib                       0x000000010b5e792d start + 1
    37  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I'm not the best as debugging in Objective-C, but let me know what I can do to help track this bug down.

markkrenek commented 8 years ago

At line 445 of REMarkerClusterer.m, mapView:regionDidChangeAnimated isn't checking the length of the selectedAnnotations array before accessing it. Use this code when calling deselectAnnotation:annotation:

id annotation = self.mapView.selectedAnnotations.firstObject;
if (annotation != nil)
    [self.mapView deselectAnnotation:annotation animated:NO];