Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
I'm trying to get an SVG importer for Cocoa. I got the code from a GNUstep project that relied on DisplayPostscript. I have ported it over to CoreGraphics, but when I call -[NSGraphicsContext graphicsPort], the resulting pointer is null and I can't use it. Would it be better for me to create a CGContextRef and link that back to NSGraphicsContext somehow?
Code is here, for those curious.
 
Last edited:

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Post your code. People are not likely to dig around your project to find WTF your are talking about.

Have you done any debugging on it? If so, what sort?

That code you gave makes no sense. A sample from one of my OS X projects looks like the following. You first have to get the context.

Code:
NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
CGContextRef contextRef = [ctx graphicsPort];
 

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
Thank you for the response.
Yeah, most of the code isn't my own: it came from another project from GNUstep. At the advice of someone on an IRC channel, I removed the NSGraphicsContext ivar.
 

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
The first time it's run, the error doesn't pop up, but when I open another SVG image, it does the null CGContextRef. It also doesn't display anything in either case.
 

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
Part of the problem is that it isn't just one function that is throwing the warning. It works on the first file, but subsequent files don't. I'm sorry but I don't know where the exact place in the code that's doing this.
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Then make a very simple test app. Learn how write to a view, say something simple like alternating color changes from a click of button. When that works repeatedly, add in reading in a jpeg and confirm you can write it to the view. After that read you SVG image and see if you can write that to the view.

You'll need to learn how to use the debugger, NSLog, and eventually Instruments. I use NSLog often for varying verifications.

Sometimes even experts use such baby steps to solve a problem.
 

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
Thanks for the feedback. I'll look into it, but now I have another issue that has cropped up when moving to ARC. I posted it in a new thread.
 

Madd the Sane

macrumors 6502a
Original poster
Nov 8, 2010
534
73
Utah
Okay, I got it to render to the image as well as not throw CGContextRef is null warnings by moving to CGLayers. Thank you for the help, though.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.