Interrupting an iPad 3 device with renderInContext

I use the following code in my application to render a custom UIView for an image. The code works great in Simulator (iPad and iPad retina), as well as on iPad 1 and iPad 2. However, I recently tested it on an iPad 3 device, and I had a crash that I can’t solve. Corresponding code snippet:

UIGraphicsBeginImageContext(CGSizeMake(myUIView.frame.size.width, myUIView.frame.size.height)); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); [myUIView.layer renderInContext:context]; 

The application crashes on the last line. The following is displayed in the crash log:

 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x12311000 Crashed Thread: 5 

And later in the magazine:

 Thread 5 name: Dispatch queue: com.apple.root.default-overcommit-priority Thread 5 Crashed: 0 ImageIO 0x3384bcb4 ImageIO_ABGR_TO_ARGB_8Bit + 68 1 ImageIO 0x3388761c __copyImageBlockSetPNG_block_invoke_1 + 608 2 libdispatch.dylib 0x348c0c52 _dispatch_call_block_and_release + 6 3 libdispatch.dylib 0x348c3810 _dispatch_worker_thread2 + 252 4 libsystem_c.dylib 0x33145df4 _pthread_wqthread + 288 5 libsystem_c.dylib 0x33145cc8 start_wqthread + 0 

At first I thought it was a memory management error, but this is only on the iPad 3 device and I use ARC. It puzzled me.

Any suggestions on where I can find to fix this problem further? Has anyone else encountered similar behavior?

Thanks in advance!

+2
source share
2 answers

Try

 UIGraphicsBeginImageContextWithOptions(CGSizeMake(myUIView.frame.size.width, myUIView.frame.size.height), NO, [[UIScreen mainScreen] scale]); 
+2
source

I finally managed to track down the source of the crash in a particular UIImageView in the view I was trying to display. This view used 2x graphics for the iPad 3 retina. Although it displayed just fine, he seemed to think he was consuming too much memory when calling renderInContext. I reduced the size of the graphics, and also reduced the scale of the rendering in the context options. This resolved the failure.

+1
source

All Articles