带有 renderInContext 的 iPad 3 设备崩溃 [英] iPad 3 Device Crash with renderInContext
问题描述
我一直在我的应用程序中使用以下代码将自定义 UIView 呈现为图像.该代码在模拟器(iPad 和 iPad Retina)以及 iPad 1 和 iPad 2 设备上运行良好.但是,我最近在 iPad 3 设备上对其进行了测试,并且遇到了我似乎无法解决的崩溃问题.相关的代码片段是:
I have been using the following code in my application to render out a custom UIView to an image. The code works great in the Simulator (iPad and iPad retina) as well as on iPad 1 and iPad 2 devices. However, I recently tested it on the iPad 3 device, and am getting a crash that I can't seem to resolve. The relevant code snippet is:
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 in the crash log:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x12311000
Crashed Thread: 5
从后面的日志中:
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
我一开始以为这是内存管理错误,但它只出现在 iPad 3 设备上,而且我使用的是 ARC.这让我很难过.
I first thought that this was a memory management error, but it's only on the iPad 3 device and I'm using ARC. This has me stumped.
有什么建议可以进一步解决这个问题吗?有没有其他人遇到过这种行为?
Any suggestions of where I might look to troubleshoot this further? Has anyone else encountered this sort of behavior?
提前致谢!
推荐答案
试试
UIGraphicsBeginImageContextWithOptions(CGSizeMake(myUIView.frame.size.width, myUIView.frame.size.height), NO, [[UIScreen mainScreen] scale]);
这篇关于带有 renderInContext 的 iPad 3 设备崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!