EXC NSOperation 中 CoreGraphics API 的错误访问
我正在尝试使用 MacRuby 在 NSOperation 内进行一些 CoreGraphics/CoreImage 操作。我有一些 API 调用,将源文件读入 CG 并设置 CGImageDestination。
如果我将以下代码放入 NSOperation.init 中,一切都会很好:
@dest = CGImageDestinationCreateWithURL(@photo.output_url, "public.jpeg" , 1, nil);
@context = CIContext.alloc.init
@cgOriginalImgSrc = CGImageSourceCreateWithURL(@photo.url, nil)
@cgOriginal = CGImageSourceCreateImageAtIndex(@cgOriginalImgSrc, 0, nil)
但是如果我将相同的代码放入 NSOperation 的主函数中,则会出现零星的 EXC_BAD_ACCESS 错误。并且仅当将 NSOperation 传递到 NSOperationQueue 时;如果我自己调用 main ,它就可以正常工作。
在主线程结束时我正在运行:
CFRelease(@dest)
CFRelease(@cgOriginalImgSrc)
CGImageRelease(@cgOriginal)
更奇怪的是它在 init 中工作,即使 init 不是从主线程调用的(所以我猜不是主线程/后台线程问题)
有什么想法吗?
I'm trying to do some CoreGraphics/CoreImage manipulation inside an NSOperation, using MacRuby. I have a few API calls that read a source file into CG and set up a CGImageDestination.
If I put the following code into an NSOperation.init, everything works great:
@dest = CGImageDestinationCreateWithURL(@photo.output_url, "public.jpeg" , 1, nil);
@context = CIContext.alloc.init
@cgOriginalImgSrc = CGImageSourceCreateWithURL(@photo.url, nil)
@cgOriginal = CGImageSourceCreateImageAtIndex(@cgOriginalImgSrc, 0, nil)
But if I put the same code into the main function for the NSOperation, I get sporadic EXC_BAD_ACCESS errors. And only when passing the NSOperation to an NSOperationQueue; if I invoke main myself, it works just fine.
At the end of the main I am running:
CFRelease(@dest)
CFRelease(@cgOriginalImgSrc)
CGImageRelease(@cgOriginal)
Even stranger is that it works in init, even if init isn't invoked from the main thread (so not a main thread/background thread issue, I'm guessing)
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您的一个线程正在引用一个不再存在于内存中的对象。尝试删除
并看看效果如何。您还可以尝试验证每个队列中的对象以查看它们是否仍然可用。最后,您可以使用 MacRubyd(MacRuby 的调试器)来查看发生了什么,甚至可以使用 GDB 并粘贴回溯,以便我们可以看到问题所在。
谢谢,
Looks like one of your threads is referring to an object that doesn't exist in memory anymore. Try removing
And see how it goes. Also you can try verifying your objects in each queue to see if they are still available. Finally, you could use macrubyd, the debugger for MacRuby to see what's going on, or even use GDB and paste the backtrace so we can see what the problem is.
Thanks,