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?