【问题标题】:CIImage drawing EXC_BAD_ACCESSCIImage 绘图 EXC_BAD_ACCESS
【发布时间】:2012-07-27 13:54:12
【问题描述】:

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

这是我调用来绘制图像的代码行:

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

outputCoreImageoriginalBounds[self bounds] 都不是nil,并且确实是它们各自的期望值。在 Lion (OS X 10.7) 上,这很好用,但是在 Mountain Lion (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];

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

我添加了这个块:

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];

看起来使用软件渲染器强制图像“解决”了问题。它有点模糊和缓慢,但不会崩溃。

【问题讨论】:

  • 只有在针对 10.8 SDK 构建时才会发生这种情况,或者在 10.8 上运行时甚至在针对 10.7 构建代码时才会发生这种情况吗?
  • 当为任何东西构建并在 10.8 上运行时会发生这种情况。在为 10.7 构建和运行时,它确实不会发生

标签: cocoa core-image osx-mountain-lion quartz-core ciimage


【解决方案1】:

在 10.8.1 中解决

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

【讨论】:

  • 在 10.8.1 中解决;将我的解决方法(或其他方法)用于较早的目标。
  • 我在 10.8.3 的 CIImage 渲染中看到 CGLGetPixelFormat 出现类似的崩溃,但仅在启用 Guard Malloc 时。有任何迹象表明这只是 Mac OS X 10.3 中的回归?
【解决方案2】:

这可能是您的应用第一次调用任何可能正在执行一些首次运行初始化或检查的 OpenGL 例程。

对于实验,请尝试在您的应用的早期添加一点 OpenGL 代码,看看是否也会崩溃。试着想想为什么调用 OpenGL 会导致崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多