-->

CIImage绘制EXC_BAD_ACCESS(CIImage drawing EXC_BAD_AC

2019-09-20 08:19发布

所以,我有一个CIImage是我试图在绘制NSView-drawRect方法。

这是我称之为绘制图像的代码行:

[outputCoreImage drawInRect: [self bounds]
                   fromRect: originalBounds
                  operation: NSCompositeSourceOver
                   fraction: 1];

outputCoreImageoriginalBounds[self bounds]都为非nil ,并且确实各自的期望值。 在狮子(OS X 10.7),这工作得很好,但是在山狮(OS X 10.8)我收到EXC_BAD_ACCESS在这条线上。 如果我走了堆栈,我发现内部函数调用,打破上CGLGetPixelFormat

frame #0: 0x00007fff99c3b26d OpenGL`CGLGetPixelFormat + 27
frame #1: 0x00007fff8fa98978 CoreImage`-[CIOpenGLContextImpl createAccelContext] + 335
frame #2: 0x00007fff8fa98d30 CoreImage`-[CIOpenGLContextImpl updateContext] + 111
frame #3: 0x00007fff8fa9a865 CoreImage`-[CIOpenGLContextImpl _lockfeContext] + 25
frame #4: 0x00007fff8fa7e4ac CoreImage`-[CIContextImpl setObject:forKey:] + 120
frame #5: 0x00007fff8fa9881c CoreImage`-[CIOpenGLContextImpl setObject:forKey:] + 259
frame #6: 0x00007fff90db93e3 libCGXCoreImage.A.dylib`cgxcoreimage_instance_render + 1477
frame #7: 0x00007fff97074ac6 CoreGraphics`CGSCoreImageInstanceRender + 32
frame #8: 0x00007fff947c89cc libRIP.A.dylib`ripc_AcquireCoreImage + 1344
frame #9: 0x00007fff947b8a00 libRIP.A.dylib`ripc_DrawShading + 9680
frame #10: 0x00007fff96cb2b2b CoreGraphics`CGContextDrawShading + 51
frame #11: 0x00007fff8fa78237 CoreImage`-[CICGContextImpl render:] + 918
frame #12: 0x00007fff8fa7d76a CoreImage`-[CIContext drawImage:inRect:fromRect:] + 1855
frame #13: 0x00007fff9897b8f3 AppKit`-[CIImage(NSAppKitAdditions) drawInRect:fromRect:operation:fraction:] + 243

我有僵尸,守卫的malloc和记录异常,所有开启,并且他们没有返回任何有用的信息。

其他的OpenGL测试:

我将此块:

CIImage *anImage  = [[CIImage alloc] init];
[[[self window] contentView] lockFocus];
{
    [anImage drawInRect: [[self window] frame]
               fromRect: [[self window] frame]
              operation: NSCompositeSourceOver
               fraction: 1];
}
[[[self window] contentView] unlockFocus];

-windowDidLoad我的方法NSWindowController 。 它运行没有问题。

我将此块:

NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://cache.virtualtourist.com/14/684723-Red_Square_Moscow.jpg"]];

CIImage *anImage  = [[CIImage alloc] initWithData: data];
[self lockFocus];
{
    [anImage drawInRect: [self bounds]
               fromRect: [anImage extent]
              operation: NSCompositeSourceOver
               fraction: 1];
}
[self unlockFocus];

另一个NSView-drawRect 。 我收到了同样的错误CGLGetPixelFormat

雷达:

在#macdev的乡亲似乎认为这是在操作系统中的问题,我不倾向于同意。 我已经提交了雷达(rdar:// 11980704)解释的问题,并链接回这个问题。

解决方法:

CGContextRef contextReference = [[NSGraphicsContext currentContext] graphicsPort];
CIContext *coreImageContext = [CIContext contextWithCGContext: contextReference
                                                      options: @{kCIContextUseSoftwareRenderer : @YES}];

[coreImageContext drawImage: outputCoreImage
                     inRect: [self bounds]
                   fromRect: originalBounds];

它看起来像迫使像使用软件渲染器“解决”的问题进行绘制。 这是一个有点模糊的和缓慢的,但它不会崩溃。

Answer 1:

解决了10.8.1

在#macdev的乡亲似乎认为这是在操作系统中的问题,我不倾向于同意。 我已经提交了雷达(rdar:// 11980704)解释的问题,并链接回这个问题。



Answer 2:

这可能是第一次您的应用程序调用到任何的OpenGL程序这可能是做一些首轮初始化或检查。

对于一个实验,尝试在你的应用程序中加入少许的OpenGL代码前面,看看是否崩溃以及。 试着想想为什么调用OpenGL可能导致飞机坠毁。



文章来源: CIImage drawing EXC_BAD_ACCESS