The app crashed on iOS 7 for map functionality developed using MKAnnotation, CGBitmapContextCreate, and NSOperationQueue

Our application implements tracking functions on the map and GPS. This app has already been downloaded to the Apple Store. The application contains the following function:

  • Map Shows traffic data in real time. Shows a traffic event in real time (accident, traffic delay, etc.).
  • Custom GPS location tracking The app works great for iOS versions 5 and 6. We are facing a crash issue for iOS 7 beta when working with Map functionality in an application. We used the following iOS features to display traffic data and traffic events on the map:

  • MKAnnotation to display traffic events

  • To display traffic data, the application uses 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 a line to display traffic data in the Bitmap context.

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

  • The application uses NSOperationQueue to display traffic data and events, since the user’s interaction with the map is smooth. The following is a snippet of code:

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

Below are two error logs that are generated during the random operation of n card functions.

Crash Log - 1

Falling

 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: XXXX 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 
+6
source share
1 answer

I think it may be that traffic events enter and lasts in NSOperation. An operation can begin, and then refer to map graphic elements that no longer exist in MapView. For example, a user can scroll through a map, and NSOperation can “stand in line” and then end when the target area leaves the field of view. A crash is clearly a memory violation. Usually caused by code trying to access freed memory.

I would suggest you study using NSOperationQueue. I see how this will make the map interaction smoother, and this part may be fine, but in combination with the “events” can cause problems.

From the crash, I see that it runs on CFRunLoop and starts NSTimer. NSTimers are notorious for not completely stopping at Objective C. When they finally fire, the elements they work with are usually executed and free their memory.

0
source

Source: https://habr.com/ru/post/955110/


All Articles