9

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.

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.

Community
  • 1
  • 1
Snel
  • 126
  • 1
  • 5
  • 2
    Just to chime in with my few cents worth, I currently have exactly the same problem. I have an NSMutableArray containing a list of objects that support the MKOverlay protocol. If an object in the mutable array is removed it is also removed from the mapview. However when I zoom repeatedly the following stack trace occurs: – Diziet Nov 16 '11 at 17:22
  • 1
    `Cannot access memory at address 0x1 (gdb) where #0 0x00000001 in ?? () #1 0x011a741c in CGPathCreateMutableCopyByTransformingPath () #2 0x01220d23 in CGContextAddPath () #3 0x003be3e1 in MKMapRectRemainder () #4 0x003be498 in MKMapRectRemainder () #5 0x003cab01 in MKTilesRequireGoogleLegalNotices () #6 0x029f3c17 in -[CALayer drawInContext:] () #7 0x02a107e3 in tiled_layer_render () #8 0x0292b127 in CAImageProviderThread () #9 0x021804e6 in _dispatch_worker_thread2 () #10 0x9c981b24 in _pthread_wqthread () #11 0x9c9836fe in start_wqthread () ` – Diziet Nov 16 '11 at 17:23
  • 2
    Thanks @Diziet for sharing. I opened a TSI at Apple Developer Network last week and then was asked to file a bug. I was told that there is no workaround available at this time and that the bug will be investigated. I'll post further comments about progress. – Snel Nov 17 '11 at 18:08
  • Excellent, I'll do the same. Good to know I'm not alone/mental. – Diziet Nov 18 '11 at 14:46
  • I don't know if this is related, but we're seeing an MKMapView issue in iOS 5 where the region value is invalid if you zoom out all of the way. Specifically, region.center.latitude + region.span.latitudeDelta/2 is 100. I don't think it should ever be over 90. Works fine in iOS 4.3. – EricS Nov 19 '11 at 02:27
  • Is there any update on this? I'm having exactly the same issue. – Undistraction Nov 24 '11 at 10:42
  • Update to all interested (@Diziet, @1ndivisible): Bug status is still open though it's been marked as a duplicate. Will post again, if there is any news. Did not yet test the issue reported by @EricS. My App never sets the span value and Map is also crashing at low values of span. – Snel Nov 25 '11 at 19:35
  • Thanks for the update. What are you doing for a workaround? Is there something really specific about the way we are using MKOverlays? Because it seems to me this bug essentially means we cannot use MKOverlays at all without crashes. – Undistraction Nov 26 '11 at 10:10
  • @1ndivisible. They told me, that there is no workaround for this at the moment. I don't think, we're doing something special or (check my example linked above). Yesterday I added TV-Out support to the app but I had to remove it immediately as the app crashed after some seconds (without zooming action) - at the same point in the code reported above. – Snel Nov 26 '11 at 20:24
  • Thanks. I've submitted a TSI of my own. Probably be told the same but worth a try. Definitely not related to zooming or panning. Can replicate every time without either. My project is totally reliant on overlays so I am screwed. – Undistraction Nov 26 '11 at 22:09
  • 1
    This is a workaround of a kind - condense all your overlays into a small number of composite overlays. https://devforums.apple.com/thread/48154?tstart=0 – Undistraction Nov 27 '11 at 16:31
  • 1
    My TSI confirmed it is a bug. Using a combination of the above link and Apple's 'Breadcrumb' example I am no longer getting crashes when using 3 overlays. So it seems 3 is safe. – Undistraction Dec 08 '11 at 14:58
  • @1ndivisible: Indeed the workaround works. I also reduced everything to just 3 overlays based on the workaround discussed in the forums-article. – Snel Dec 08 '11 at 20:06
  • Nice. Definitely worth having a look at Apple's Breadcrumb example if you haven't already. There are some nasty quirks to Overlays / OverlayViews that aren't apparent at first. It's very important to make them thread safe to avoid unnecessary redraws. – Undistraction Dec 09 '11 at 11:53

2 Answers2

3

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.

David Hodge
  • 1,724
  • 15
  • 13
  • Tanks @David for sharing your thoughts. In my example I indeed missed to set the delegate of the mapView to nil before releasing. I never thought about this, because the map crashes while being used and drawing the map. I updated the example with ` self.theMapView.delegate = nil; [self.theMapView release]; self.theMapView = nil;` The example code never does a `performSelector`. For now, the crashing persists. – Snel Nov 28 '11 at 02:29
0

remove the method zoomToPolyLine and use mapViewDidUpdateLocation to zoom on poly line.

Muhammad Anum
  • 136
  • 16