Question

I'm trying to build a MacRuby 0.12 project on OSX 10.8. The problem appears to be that this line:

 @context = NSGraphicsContext.currentContext.graphicsPort

throws this error:

unrecognized runtime type `{CGContext=}' (TypeError)

I can dereference NSGraphicsContext.currentContext just fine, but currentContext.graphicsPort fails at runtime.

From some random Google-ing around, it appears that MacRuby is not linking to CoreGraphics properly. I tried adding the ApplicationServices.framework explicitly, but that didn't help. To add to the confusion, the exact some project freshly checked out on my friend's nearly-identical setup works just fine, so the issue is likely with my system's configuration rather than project settings.

Has anyone encountered this before, and can offer some advice?

Was it helpful?

Solution

Okay, so after a lot of help from @jballanc on the #macruby IRC client, we determined that this is a Mountain Lion-specific problem caused by some changes to the way CoreGraphics is packaged in the latest XCode. Here's how to solve it if you're running into it:

  1. Regenerate your Bridge Support files for both CoreGraphics and ApplicationServices, using something like:

    gen_bridge_metadata --64-bit -f /System/Library/Frameworks/CoreGraphics.framework/ -o /System/Library/Frameworks/CoreGraphics.framework/Resources/BridgeSupport/CoreGraphics.bridgesupport

  2. In Mountain Lion, you will need to explicitly load the CoreGraphics framework from your MacRuby code -- but in versions previous to Mountain Lion, doing so will crash. So you'll need something like the following check:

    framework 'CoreGraphics' if (/12/ =~ `uname -r`) == 0

  3. Depending on your environment, you may or may not need to explicitly link against ApplicationServices.framework in your XCode project settings.

Doing all of the above allowed me and my Snow Leopard-using partner to share the same code base and have it work for both of us.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top