mapview overlay crash

Discussion in 'iOS Programming' started by MACloop, Apr 24, 2012.

  1. MACloop macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #1
    Hello,
    I have an app where I put a custom overlay on a mapview (code below). I have 2 iphones to test on one with 5.0.1 and one with 5.1 and on the 5.1 device the overlay is causing a crash. Everything works fine till the moment when the image is supposed to be added.

    I've tried pretty much everything and cant see what is wrong :-( The map is only loading properly when the images isnt added.

    1) is anything wrong in my implementionen? Am I missing something? It works on my device with ios5.0.1 thou
    2) has the implementation of overlays been adjusted in ios5.1?
    3) Anyone else seen the same problem? I've another app build and relesed earlier and its based on the same solution. This app still works on the 5.1 device... can the compiler and the newer xcode version be the problem?

    I would be very thankful for any hints on this issue... I have tried everything I could think of and really dont know where to look more :-(

    Thanks in advance!
    MACloop


    This is my solution:
    //call from viewcontroller with mapView
    Code:
     
    ...
    CLLocationCoordinate2D lowerLeft = CLLocationCoordinate2DMake(south,west);
    			CLLocationCoordinate2D upperRight = CLLocationCoordinate2DMake(north,east);
    	
                CustomOverlay *co = [[CustomOverlay alloc]initWithLowerLeftCoordinate:lowerLeft withUpperRightCoordinate:upperRight];
    
                [map addOverlay:co];
                [co release];
    
    //and the delegate method in the same class:
    Code:
    - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)oly{
        CustomOverlay *c =  (CustomOverlay *)oly;
       CustomOverlayView* ov = [[CustomOverlayView alloc] initWithOverlay:c];
    	return [ov autorelease];
    }
    

    //custom overlay
    Code:
    - (id) initWithLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate{	
    	MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
    	MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
    	self.mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
    	return self;
    }
    
    - (id)delegate {
    	return self.delegate;
    }
    
    
    - (void)setDelegate:(id <CustomOverlayDelegate>)newDelegate {
    	self.delegate = newDelegate;
    }
    
    
    - (CLLocationCoordinate2D)coordinate{
    	return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(self.mapRect), MKMapRectGetMidY(self.mapRect)));
    }
    
    
    - (MKMapRect)boundingMapRect{
    	return self.mapRect;
    }
    //custom overlayView

    Code:
    - (id)initWithOverlay:(id<CustomOverlayDelegate>) o {
    	self = [super initWithOverlay:o];
    	self.overlayToUse = o;
    	return self;
    }
    
    -(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    
        MKMapRect theMapRect = [self.overlayToUse boundingMapRect];
        CGRect theRect = [self rectForMapRect:theMapRect];
    
    	UIImage *image = [UIImage imageNamed:[self.overlayToUse overlay_image_path]];    
    
    	UIGraphicsPushContext(context);
    	[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
      
    	UIGraphicsPopContext();
    }
    
    -(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
    	return YES;
    }
     
  2. cMacSW macrumors regular

    Joined:
    Mar 20, 2006
    #2
    Did you look at the crashlogs? Any hint in there?
     
  3. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #3
    This is what the device log says and I cant read much out of that:
    Code:
    Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes: KERN_INVALID_ADDRESS at 0x05c74000
    Crashed Thread:  7
    
    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0:
    0   libsystem_kernel.dylib        	0x34f9e004 mach_msg_trap + 20
    1   libsystem_kernel.dylib        	0x34f9e1fa mach_msg + 50
    2   CoreFoundation                	0x3518e3ec __CFRunLoopServiceMachPort + 120
    3   CoreFoundation                	0x3518d0ea __CFRunLoopRun + 818
    4   CoreFoundation                	0x3511049e CFRunLoopRunSpecific + 294
    5   CoreFoundation                	0x35110366 CFRunLoopRunInMode + 98
    6   GraphicsServices              	0x3640c432 GSEventRunModal + 130
    7   UIKit                         	0x32206e76 UIApplicationMain + 1074
    8   LGS Bamberg                   	0x000f8978 main (main.m:13)
    9   LGS Bamberg                   	0x000f8930 0xf7000 + 6448
    
    Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
    Thread 1:
    0   libsystem_kernel.dylib        	0x34f9e3a8 kevent + 24
    1   libdispatch.dylib             	0x311ebea4 _dispatch_mgr_invoke + 708
    2   libdispatch.dylib             	0x311ebbc2 _dispatch_mgr_thread + 30
    
    Thread 2 name:  WebThread
    Thread 2:
    0   libsystem_kernel.dylib        	0x34f9e004 mach_msg_trap + 20
    1   libsystem_kernel.dylib        	0x34f9e1fa mach_msg + 50
    2   CoreFoundation                	0x3518e3ec __CFRunLoopServiceMachPort + 120
    3   CoreFoundation                	0x3518d124 __CFRunLoopRun + 876
    4   CoreFoundation                	0x3511049e CFRunLoopRunSpecific + 294
    5   CoreFoundation                	0x35110366 CFRunLoopRunInMode + 98
    6   WebCore                       	0x36f930f0 _ZL12RunWebThreadPv + 396
    7   libsystem_c.dylib             	0x36e6b72e _pthread_start + 314
    8   libsystem_c.dylib             	0x36e6b5e8 thread_start + 0
    
    Thread 3 name:  com.apple.NSURLConnectionLoader
    Thread 3:
    0   libsystem_kernel.dylib        	0x34f9e004 mach_msg_trap + 20
    1   libsystem_kernel.dylib        	0x34f9e1fa mach_msg + 50
    2   CoreFoundation                	0x3518e3ec __CFRunLoopServiceMachPort + 120
    3   CoreFoundation                	0x3518d124 __CFRunLoopRun + 876
    4   CoreFoundation                	0x3511049e CFRunLoopRunSpecific + 294
    5   CoreFoundation                	0x35110366 CFRunLoopRunInMode + 98
    6   Foundation                    	0x30fdcbb2 +[NSURLConnection(Loader) _resourceLoadLoop:] + 302
    7   Foundation                    	0x30fdca7a -[NSThread main] + 66
    8   Foundation                    	0x3107058a __NSThread__main__ + 1042
    9   libsystem_c.dylib             	0x36e6b72e _pthread_start + 314
    10  libsystem_c.dylib             	0x36e6b5e8 thread_start + 0
    
    Thread 4 name:  com.apple.CFSocket.private
    Thread 4:
    0   libsystem_kernel.dylib        	0x34fae570 __select + 20
    1   CoreFoundation                	0x3519263a __CFSocketManager + 726
    2   libsystem_c.dylib             	0x36e6b72e _pthread_start + 314
    3   libsystem_c.dylib             	0x36e6b5e8 thread_start + 0
    
    Thread 5 name:  Dispatch queue: com.apple.root.default-priority
    Thread 5:
    0   libsystem_kernel.dylib        	0x34f9e054 semaphore_wait_trap + 8
    1   libdispatch.dylib             	0x311ec3a2 _dispatch_group_wait_slow + 146
    2   libdispatch.dylib             	0x311ec302 dispatch_group_wait$VARIANT$up + 22
    3   ImageIO                       	0x35a11ee0 copyImageBlockSetPNG + 1716
    4   ImageIO                       	0x35a11458 ImageProviderCopyImageBlockSetCallback + 412
    5   CoreGraphics                  	0x31b524b6 CGImageProviderCopyImageBlockSetWithOptions + 186
    6   CoreGraphics                  	0x31b57af8 CGImageProviderCopyImageBlockSet + 24
    7   CoreGraphics                  	0x31b5215a img_blocks_create + 374
    8   CoreGraphics                  	0x31b696ca img_blocks_extent + 50
    9   CoreGraphics                  	0x31b764c0 img_interpolate_extent + 96
    10  CoreGraphics                  	0x31b4e208 img_data_lock + 4156
    11  CoreGraphics                  	0x31b4cac2 CGSImageDataLock + 150
    12  libRIP.A.dylib                	0x37a67f92 ripc_AcquireImage + 1390
    13  libRIP.A.dylib                	0x37a612b8 ripc_DrawImage + 512
    14  CoreGraphics                  	0x31b4c922 CGContextDelegateDrawImage + 42
    15  CoreGraphics                  	0x31b4c78e CGContextDrawImage + 286
    16  UIKit                         	0x321efc16 -[UIImage drawInRect:blendMode:alpha:] + 1154
    17  LGS Bamberg                   	0x00105284 -[CustomOverlayView drawMapRect:zoomScale:inContext:] (CustomOverlayView.m:28)
    18  MapKit                        	0x34d7ff2e 0x34d22000 + 384814
    19  QuartzCore                    	0x36caa4de -[CALayer drawInContext:] + 110
    20  QuartzCore                    	0x36d67652 _ZL18tiled_layer_renderP16_CAImageProviderjjjjPv + 918
    21  QuartzCore                    	0x36cfa36e _ZL21CAImageProviderThreadPjb + 362
    22  libdispatch.dylib             	0x311eb7b4 _dispatch_worker_thread2 + 256
    23  libsystem_c.dylib             	0x36e65df4 _pthread_wqthread + 288
    24  libsystem_c.dylib             	0x36e65cc8 start_wqthread + 0
    
    Thread 6 name:  Dispatch queue: com.apple.root.default-overcommit-priority
    Thread 6:
    0   libsystem_kernel.dylib        	0x34fae0a0 __psynch_mutexdrop + 24
    1   libsystem_c.dylib             	0x36e5fe5a pthread_mutex_unlock + 250
    2   ImageIO                       	0x35a0d5f8 CGImageReadGetBytesAtOffset + 592
    3   ImageIO                       	0x35a50728 read_fn2 + 112
    4   ImageIO                       	0x35a0d332 png_read_data + 6
    5   ImageIO                       	0x35a0d972 png_crc_read + 14
    6   ImageIO                       	0x35a135a6 png_read_row + 450
    7   ImageIO                       	0x35a50604 __copyImageBlockSetPNG_block_invoke_1 + 584
    8   libdispatch.dylib             	0x311dfc52 _dispatch_call_block_and_release + 6
    9   libdispatch.dylib             	0x311eb7b4 _dispatch_worker_thread2 + 256
    10  libsystem_c.dylib             	0x36e65df4 _pthread_wqthread + 288
    11  libsystem_c.dylib             	0x36e65cc8 start_wqthread + 0
    
    Thread 7 name:  Dispatch queue: com.apple.root.default-overcommit-priority
    Thread 7 Crashed:
    0   ImageIO                       	0x35a14cb4 ImageIO_ABGR_TO_ARGB_8Bit + 68
    1   ImageIO                       	0x35a5061c __copyImageBlockSetPNG_block_invoke_1 + 608
    2   libdispatch.dylib             	0x311dfc52 _dispatch_call_block_and_release + 6
    3   libdispatch.dylib             	0x311eb7b4 _dispatch_worker_thread2 + 256
    4   libsystem_c.dylib             	0x36e65df4 _pthread_wqthread + 288
    5   libsystem_c.dylib             	0x36e65cc8 start_wqthread + 0
    
    Thread 8 name:  NetworkIO
    Thread 8:
    0   libsystem_kernel.dylib        	0x34f9e004 mach_msg_trap + 20
    1   libsystem_kernel.dylib        	0x34f9e1fa mach_msg + 50
    2   CoreFoundation                	0x3518e3ec __CFRunLoopServiceMachPort + 120
    3   CoreFoundation                	0x3518d124 __CFRunLoopRun + 876
    4   CoreFoundation                	0x3511049e CFRunLoopRunSpecific + 294
    5   CoreFoundation                	0x35110366 CFRunLoopRunInMode + 98
    6   MapKit                        	0x34d30e16 0x34d22000 + 60950
    7   Foundation                    	0x30fdca7a -[NSThread main] + 66
    8   Foundation                    	0x3107058a __NSThread__main__ + 1042
    9   libsystem_c.dylib             	0x36e6b72e _pthread_start + 314
    10  libsystem_c.dylib             	0x36e6b5e8 thread_start + 0
    
    Thread 7 crashed with ARM Thread State:
        r0: 0x045d7f3c    r1: 0x00000bb8      r2: 0x00000001      r3: 0x0e3a2e00
        r4: 0x00000000    r5: 0x00000177      r6: 0x05c74000      r7: 0x045d7ed4
        r8: 0x0e3a3220    r9: 0x00000157     r10: 0x00000000     r11: 0x00120997
        ip: 0x05c73c00    sp: 0x045d7ebc      lr: 0x00000bb8      pc: 0x35a14cb4
      cpsr: 0x200f0030
    

    And this is a screen shot from the crash in xcode (please see attachment)
     

    Attached Files:

  4. cMacSW macrumors regular

    Joined:
    Mar 20, 2006
    #4
    So from the crash log:

    and a little further down

    It's failing during this call with a Invalid Address:

    Did you verifiy that image is loaded sucessfully before calling this?

    ----------

    Also, is ther any info in the console log in xcode?
     
  5. MACloop thread starter macrumors 6502

    Joined:
    May 18, 2009
    Location:
    Germany
    #5
    Thanks for the answers so far! I have the images in the main bundle under the resources-group ... I just tried to call it this way instead:

    Code:
    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"theImagesName" ofType:@"png"]]; 
    	UIGraphicsPushContext(context);
    	[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
    	UIGraphicsPopContext();
    
    but it gave the same result... The console doesnt say anything... unfortunately...

    Thanks for the help so far - I really appreciate it!
     
  6. cMacSW macrumors regular

    Joined:
    Mar 20, 2006
    #6
    I would set a breakpoint here:

    Code:
    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"theImagesName" ofType:@"png"]]; 
    	UIGraphicsPushContext(context);
    	[image drawInRect:theRect blendMode:kCGBlendModeNormal alpha:1.0];
    	UIGraphicsPopContext();
    I'd check to see if the image is not nil, and step line by line to confirm that the drawInRect call is indeed failing.
     

Share This Page