Cocoa CIImage图纸交换错误访问

Cocoa CIImage图纸交换错误访问,cocoa,core-image,osx-mountain-lion,quartz-core,ciimage,Cocoa,Core Image,Osx Mountain Lion,Quartz Core,Ciimage,因此,我有一个CIImage,我正试图在NSView的-drawRect方法中绘制它 这是我用来绘制图像的代码行: [outputCoreImage drawInRect: [self bounds] fromRect: originalBounds operation: NSCompositeSourceOver fraction: 1]; outputCoreImage、原始边界

因此,我有一个
CIImage
,我正试图在
NSView
-drawRect
方法中绘制它

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

[outputCoreImage drawInRect: [self bounds]
                   fromRect: originalBounds
                  operation: NSCompositeSourceOver
                   fraction: 1];
outputCoreImage
原始边界
[自边界]
都是非
nil
,实际上是它们各自的期望值。在Lion(OS X 10.7)上,这很好,但是在Mountain Lion(OS X 10.8)上,我在这行上收到了一个
EXC\u BAD\u访问
。如果我沿着堆栈向上走,我会发现中断的内部函数调用在
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测试:

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

[coreImageContext drawImage: outputCoreImage
                     inRect: [self bounds]
                   fromRect: originalBounds];
我添加了以下内容:

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];
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];
到我的
NSWindowController
-windowDidLoad
方法。它运行没有问题

我添加了以下内容:

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];
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
上收到了相同的错误

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
雷达:

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

[coreImageContext drawImage: outputCoreImage
                     inRect: [self bounds]
                   fromRect: originalBounds];
macdev的同事们似乎认为这是操作系统的问题,我不想不同意。我装了雷达(rdar://11980704)解释问题并链接回此问题

解决方法:

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

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

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

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

作为一个实验,尝试在你的应用程序中添加一点OpenGL代码,看看是否也会崩溃。试着想想为什么调用OpenGL可能会导致崩溃。

在10.8.1中解决
macdev的同事们似乎认为这是操作系统的问题,我不想不同意。我装了雷达(rdar://11980704)解释问题并链接回此问题。

是否只有在针对10.8 SDK构建时才会发生这种情况,或者在10.8上运行时,甚至在针对10.7构建代码时才会发生这种情况?在针对任何内容构建并在10.8上运行时才会发生这种情况。在10.8.1中所述的10.7.1版本上建造和运行时不会发生这种情况;对早期目标使用我的解决方法(或其他方法)。我在10.8.3版的
CIImage
渲染中看到类似的崩溃,但仅在启用Guard Malloc时。有没有迹象表明这只是Mac OS X 10.3中的倒退?