Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5 MapKit Crashes with Overlays when zoom/pan

I have build an app which is intended to display some overlays. The overlays are in form of polygons with up to 10000 points in the outer ring. But the high number of points seems not to be the problem here. In the last few days I kept simplifying my app just to find myself with a simple View containing a MapView. The View is Loaded from a xib (with outlets and delegate connected). The overlay is created within the method - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated and added to the mapView.

The demonstration (which is available here https://github.com/nebucaz/mapkit) shows a MapView and adds a red triangle whenever the map is zoomed-in/out or panned. When playing around zooming and panning (intensively and fast) the MapView, the app crashes. It's easy to chars the simulator, on the device it is much harder even though it is possible (I can provide crash-log).

There are two demos: MapCrash and MapCrashStatic. The first creates multiple polygons around the map depending on where one pans/zooms. The second only has a single, static polygon which is created in -(void) viewDidLoad and then is added on every call of mapView regionDidChangeAnimated

App always crashes with the following backtrace:

Attaching to process 8745.
MapCrash(8745) malloc: protecting edges
[Switching to process 8745 thread 0x1820b]
[Switching to process 8745 thread 0x1820b]
(gdb) backtrace
#0  0x00000000 in ?? ()
#1  0x00e81a60 in CG::Path::apply_transform ()
#2  0x00ed741c in CGPathCreateMutableCopyByTransformingPath ()
#3  0x00f50d23 in CGContextAddPath ()
#4  0x000f11dc in MKRoadWidthAtZoomScale ()
#5  0x000ee498 in MKMapRectRemainder ()
#6  0x000fab01 in MKTilesRequireGoogleLegalNotices ()
#7  0x02723c17 in -[CALayer drawInContext:] ()
#8  0x027407e3 in tiled_layer_render ()
#9  0x0265b127 in CAImageProviderThread ()
#10 0x01eb04e6 in _dispatch_worker_thread2 ()
#11 0x98f44b24 in _pthread_wqthread ()
#12 0x98f466fe in start_wqthread ()
(gdb) 

The Backtrace is always the same, it crashes at the same point in the library code. I analyzed with instruments (zombies,leaks, allocations) and also made some test with over-retained objects. I assumed it to be a memory-problem but I was not yet able to start up Malloc Guard. The crash may be reproduced on multiple machines - even tough I just re-installed Xcode-tools.

Other posts on stackoverflow.com also deal with sudden crash in MapKit, but either offer no direct solution for my problem or had to deal with delegate and other view-transition or application start/stop issues. ARC is off in my projects.

  • Navigation and MapKit makes app crash
  • IOS - Mapkit crash - Is it a bug in xcode 4.2 and Automatic Reference Counting (ARC)?
  • MKMapView crash (Annotations)
  • I need help with a MKMapView crash (Delegate)

I hunt this crash for more than a week now, still assuming that I misinterpreted the KMLViewer Demo (Apple) or doing something the wrong way (Credits to other iOS developers in my neighborhood!)

Nevertheless, I would appreciate your suggestions and help in this matter.

like image 212
Snel Avatar asked Nov 05 '11 19:11

Snel


1 Answers

You probably already thought about this, but I have seen numerous distinct-looking crashers from MapKit all stemming from not nil-ing out the delegate. Just make sure you set the map view's delegate to nil before you release it.

Additionally, I've seen a number of developers inclined to use performSelector:afterDelay: on their map view. That's fine so long as you put a cancelperform call in the right places too.

like image 93
David Hodge Avatar answered Sep 21 '22 00:09

David Hodge