27

I've an app on the apple store and after the iOS6 update I've got hundred of crash report within MKMapView. I cannot manage to reproduce the crash on my devices. It looks like a problem with EAGLContext. We don't use OpenGL in our app but we have more than one instances of MKMapView in different controller. I've found a similar issue here iOS 6 app crashes in EAGLContext when displaying maps but they use OpenGL.

Here there is the backtrace:

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x1
Crashed Thread:  0

Thread 0 Crashed:
0   libGPUSupportMercury.dylib          0x00000e22 gpus_ReturnNotPermittedKillClient + 10
1   libGPUSupportMercury.dylib          0x3bccc5fb gldCreateContext + 190
2   GLEngine                            0x344c2b15 gliCreateContextWithShared + 676
3   OpenGLES                            0x0000491d -[EAGLContext initWithAPI:properties:] + 1433
4   OpenGLES                            0x000042d7 -[EAGLContext initWithAPI:sharedWithCompute:] + 143
5   VectorKit                           0x00011c81 -[VGLGPU init] + 105
6   VectorKit                           0x000d4659 __24+[VGLGPU sharedInstance]_block_invoke_0 + 49
7   libdispatch.dylib                   0x000014b7 _dispatch_client_callout + 23
8   libdispatch.dylib                   0x000073f7 dispatch_once_f$VARIANT$mp + 43
9   VectorKit                           0x00011c13 +[VGLGPU sharedInstance] + 39
10  VectorKit                           0x00001db1 -[VKMainLoop updateLinkState] + 485
11  VectorKit                           0x00001955 -[VKScreenCanvas _updateDisplayStatus:] + 109
12  UIKit                               0x0001c371 -[UIView initWithFrame:] + 129
13  VectorKit                           0x00010ca5 -[VGLScreenCanvas initWithFrame:context:] + 53
14  VectorKit                           0x00010a7d -[VKScreenCanvas initWithFrame:context:] + 57
15  VectorKit                           0x00010a3f -[VKScreenCanvas initWithFrame:] + 39
16  VectorKit                           0x000106bd -[VKMapCanvas initWithFrame:shouldRasterize:] + 65
17  VectorKit                           0x000104bb -[VKMapView initWithFrame:andGlobe:shouldRasterize:] + 647
18  MapKit                              0x0000dc95 -[MKMapView _commonInitAndEnableLoading:fromIB:] + 725
19  MapKit                              0x0000d811 -[MKMapView initWithFrame:] + 257
.....
Community
  • 1
  • 1
Breezeight
  • 1,855
  • 2
  • 22
  • 27
  • Are you sure that it is not because of memory leak? I'm experiencing a similar problem but I've already identified the cause. The iOS 6 MKMapView is taking 10x more memory than the previous one. My App is all about showing stuffs on maps and its footprint increased from 30MB to 280MB. I'm trying to solve it, but no clue yet. – Trein Oct 05 '12 at 03:38
  • Hi @trein, the exception is SIGSEGV, from what I understand this should be caused by a bad memory access. – Breezeight Oct 16 '12 at 19:06

4 Answers4

24

We were having a similar problem when user's background our app just as we're popping up a window that includes a map subview. The crash seemed to be happening due to the map using an openGL call while we're backgrounded. We had to wrap the map subview creation in a check like the following:

UIApplicationState appState = [[UIApplication sharedApplication] applicationState];
    if( (appState != UIApplicationStateBackground) && (appState != UIApplicationStateInactive))
    {
        // Do map subview initialization...
    }
    else
    {
        self.attemptedToLoadMap = YES;
    }

We saved off the bool so that if the app comes back to the foreground we can add the subview in for display.

You have to do this anytime you're manipulating the map in a way that causes a re-draw operation (e.g., adding an annotation).

stuckj
  • 977
  • 1
  • 13
  • 24
  • Hi @stuckj, does it fix your crash? – Breezeight Oct 30 '12 at 15:52
  • App was approved over the weekend. And, yep, it seems to have addressed it. Not seeing reports of it anymore in crash reporting. – stuckj Nov 05 '12 at 22:17
  • Any ideas of why you also have to check for UIApplicationStateInactive? I mean the app's UI is still visible, it's just not frontmost. I added a check for UIApplicationStateBackground only and I'm still getting crash reports for this. – samvermette Feb 05 '13 at 23:21
  • You hit the inactive state before entering the background. By the time your state is UIApplicationStateBackground you're already in the background so you're already at risk of having a map UI operation kill things before this check was performed. Checking for inactive as well closes that window more. It probably still is POSSIBLE to get a crash even with this check, but it should close the window much more. – stuckj Feb 06 '13 at 18:47
  • Hmm. Our Map View is created via a NIB. Why am I getting the sneaking suspicion that this is no longer a good idea. :-o – Joe D'Andrea Feb 18 '13 at 20:24
  • Actually, if I may ask, I do add/remove annotations from time to time, but by that point the map is already created (of course, hence the redraw). Does that really mean I'd leave the NIB alone and just do reality checks when handling annotations? (Although in my case the crash does occur after initWithCoder: is called, so perhaps its more tricky to solve.) – Joe D'Andrea Feb 18 '13 at 21:47
  • If you're getting a similar stack trace (ending in gpus_ReturnNotPermittedKillClient) from initWithCoder than it sounds like your NIB with the map is being initialized when in the background (or at least starts near when you're backgrounding). I don't know that using a NIB specifically would cause a problem, but it gives you less control on when it's initialized so you might want to switch to programatic initialization. We did it in a singleton (also mitigates some terrible memory leaks the iOS maps have...). – stuckj Feb 19 '13 at 21:01
  • Thanks, stuckj - appreciated. Indeed, I am getting that exact same stack trace. Our map view is part of a view shown within a nav controller, which is itself in a tab bar controller. Thus there are NIB initializations to spare. I moved the map view out of the NIB to see if that helps ... but now you have me curious about that singleton. Hmm! – Joe D'Andrea Feb 20 '13 at 14:47
  • The singleton idea we really just did to get around a memory problem (not sure if it's fixed in 6.1...haven't checked yet). We were seeing massive amounts of memory leaked every time the map view went away. Probably cache, but effectively was a leak since it would cause increased memory pressure leading to crashes. Especially if people used the camera in the app after the map went away. – stuckj Feb 21 '13 at 18:21
3

http://developer.apple.com/library/ios/#qa/qa1766/_index.html

This Technical QA address this issue

futbolpal
  • 1,388
  • 2
  • 13
  • 19
  • 2
    I don't use OpenGL, but Apple does for iOS 6 maps. Perhaps they should be following their own Technical Q&A in this case? Eek. – Joe D'Andrea Feb 18 '13 at 20:25
  • Poor choice of words. It slightly explains what is happening, but in the case where an Apple provided framework (MapKit) is responsible, it does not explain how to "address" the issue – software evolved May 28 '15 at 14:59
3

We found the cause of this in our app so I wanted to post the solution in case it would help anyone else. Our primary view controller monitors significant location changes when it is displayed and stops monitoring when it is hidden. Some number of our users experienced an unrelated crash on this screen, which left the app monitoring. When an app has registered for significant location change updates, iOS will actually launch the app into the background if it is not running to tell it about the new location. Since our app displays a map when it first comes up, this caused a crash. Apple support confirmed with us that there is a bug on 32 bit devices running iOS 8.x that may cause a crash if a MapView (or other OpenGL context) is updated while the app is in the background.

We changed our code so that if the app is launched due to a significant location change we immediately stop monitoring and throw an exception to crash the app. This is completely invisible to the user so they do not notice the crash, and it prevents further crashes from happening.

- (void)validateLaunchWithOptions:(NSDictionary *)launchOptions
{
    if (launchOptions[@"UIApplicationLaunchOptionsLocationKey"]) {
        // the app was launched due to a significant location change, which is not valid and causes crashes
        // prevent this from happening again by disabling significant location monitoring
        CLLocationManager *locationManager = [[CLLocationManager alloc] init];
        [locationManager stopMonitoringSignificantLocationChanges];

        // intentionally crashing the app here; it is not in a good state and it needs to be prevented from
        // getting to any code that would re-enable significant location monitoring
        @throw [NSException exceptionWithName:@"com.redacted.significantLocationLaunch"
                                       reason:@"app may not be launched due to significant location changes"
                                     userInfo:@{}];
    }
}

We saw thousands of this crash but were not able to duplicate it on our test devices until we figured out the cause. If you would like to duplicate it (and also confirm the fix), @throw an exception immediately after your app starts monitoring significant location changes. After the app crashes, go take a drive. As soon as your phone switches cell towers iOS will launch the app in the background and you will get the crash. We were able to get our hands on one of our users phones and inspect the crash logs. All of the crashes happened during her commute to and from work.

2

I'm facing a similar stack trace. I noticed that in the console it is giving more detail on the actual problem: you can't use the GPU while in the background. The maps with iOS 5 were tile based so I assume didn't use the GPU, but the new maps in iOS 6 use vector graphics and thus the GPU. As a result, any map work that used to be in the background no longer can be.

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
hunterhacker
  • 6,378
  • 1
  • 14
  • 11
  • Hi @hunterhacker, I'm getting this stack trace from users. I cannot manage to reproduce the crash on may own device. Could you help me to reproduce the bug? – Breezeight Oct 16 '12 at 19:14
  • I couldn't recreate it in the simulator, probably because the simulator doesn't use the GPU for map generation. The trace happened reliably whenever I tried to create a new map view while running in the background getting a callback about a new user location. Sorry for the delay in replying, not sure how I'm supposed to be notified of comments on answers but I didn't get it. – hunterhacker Nov 15 '12 at 06:12