Pergunta

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?

Foi útil?

Solução

Looks like one of your threads is referring to an object that doesn't exist in memory anymore. Try removing

CFRelease(@dest)    
CFRelease(@cgOriginalImgSrc)
CGImageRelease(@cgOriginal)

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,

  • Matt
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top