App crashed on iOS 7 for Map functionality developed using MKAnnotation, CGBitmapContextCreate and NSOperationQueue

6

Our App has Map and GPS based location tracking functionality. This app is already uploaded on Apple Store. The App contains following feature:

  • Map Shows real-time traffic data Shows real-time traffic event (Accident, Traffic Jam etc.)
  • User’s GPS location tracking The application runs fine for the iOS versions 5 and 6. We are facing following crashing issue for iOS 7 Beta while operating Map functionality in the app. We have used the following features of iOS to render the traffic data and traffic event on Map:

  • MKAnnotation to render the traffic event

  • To render the traffic data, app is using the CGBitmapContextCreate function.

    context = CGBitmapContextCreate (NULL,
                                    self.mapView.frame.size.width,                                                    
                                    self.mapView.frame.size.height, 
                                    8,// bits per component
                                    bitmapBytesPerRow,
                                    colorSpace,
                                    kCGImageAlphaPremultipliedLast);
    
    CGContextSetAllowsAntialiasing (context,YES)
    
  • Draw the line to display the traffic data on the Bitmap context.

  • Created bitmap context will be displayed on map using the MKAnnotation API.

  • App uses the NSOperationQueue to render the traffic and event data because the user interaction with map is smooth. Following is the snippet of the code:

     [queue addOperationWithBlock:^{ [Set the required data], [Update the UI] }];
    

Following are two crash logs which gets generated while random operation n of the Map functionality.

Crash Log - 1

Incident

Identifier: 471EAE21-E118-4E3D-AAAE-D7D82B1D6326

CrashReporter

Key:

bdbf75eb30240449214769478f38830aa7a14f7f

Hardware

Model:      iPhone5,2

Process:             {Application Name} [246]

Path:                /var/mobile/Applications/4FA0A7F2-4998-4F8F-A4C6-66D849D074B8/{Application Name}.app/{Application Name}

Identifier:          {Application bunald name}

Version:             X.X.X.X

Code

Type:           ARM (Native)

Parent

Process:      launchd [1]

Date/Time:           2013-08-30 14:21:24.523 +0530

OS

Version:          iOS 7.0 (11A4449d)

Report

Version:      104

Exception

Type:  EXC_BAD_ACCESS (SIGSEGV)

Exception

Subtype: KERN_INVALID_ADDRESS at 0x8000000c

Triggered

by Thread:  0

Thread

0 Crashed:

0   libobjc.A.dylib                 0x38ed3b66

objc_msgSend + 6

1   CoreFoundation                              0x2ede773c -[__NSSetM removeObject:] + 92

2   MapKit                              0x3002de96 -[MKAnnotationManager

_removeRepresentationForAnnotation:fromCull:] + 490

3   MapKit                              0x3004bc54 -[MKAnnotationManager

_removeAnnotation:updateVisible:removeFromContainer:] + 272

4   MapKit                              0x3004bb38 -[MKAnnotationManager removeAnnotation:] + 24

5   SLIM                                  0x00165828 -[TravelStarViewController

mapView:viewForAnnotation:] (TravelStarViewController.m:1735)

6   MapKit                              0x3005ea86 -[MKMapView

annotationManager:representationForAnnotation:] + 74

7   MapKit                              0x3002a136 -[MKAnnotationManager _addRepresentationForAnnotation:]

+ 362

8   MapKit                              0x30028c4a -[MKAnnotationManager updateVisibleAnnotations] +

1034

9   Foundation                      0x2f876358 __NSFireTimer + 60

10  CoreFoundation                            0x2ee7ae84 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__

+ 12

11  CoreFoundation                            0x2ee7aa9e __CFRunLoopDoTimer + 790

12  CoreFoundation                            0x2ee78e26 __CFRunLoopRun + 1214

13  CoreFoundation                            0x2ede353c CFRunLoopRunSpecific + 520

14  CoreFoundation                            0x2ede331e CFRunLoopRunInMode + 102

15  GraphicsServices                           0x3387733e

GSEventRunModal + 134

16  UIKit                                 0x313fc7b0 UIApplicationMain + 1132

17  SLIM                                 0x000f3fa6

main (main.m:15)

18  SLIM                                 0x000f3efc start + 36
iphone
objective-c
cocoa-touch
ios7
asked on Stack Overflow Oct 2, 2013 by (unknown user) • edited Mar 24, 2014 by Vladimir

1 Answer

0

I think it may be that traffic events are coming in and taking to long in NSOperation. The operation could start, and then be referencing map graphical elements that no longer exist in the MapView. For instance, the user could be scrolling the map, and the NSOperation could "queue" up, and then end when the target region is out of view. The crash is clearly a memory violation. Commonly caused by code trying to access memory that was freed.

I would suggest that you look into your use of NSOperationQueue. I can see how it would make the map interaction smoother, and that part may be OK, but coupled with the "events" could be causing problems.

From the crash I can see that it is running on a CFRunLoop and a NSTimer is firing. NSTimers are notorious for not stopping fully in Objective C. When they finally fire off, the elements they work with are commonly done and freed their memory.

answered on Stack Overflow Apr 2, 2014 by Schlank

User contributions licensed under CC BY-SA 3.0