PDA

View Full Version : [Resolved] [NSGraphicsContext graphicsPort] returning null




Madd the Sane
Mar 25, 2012, 03:35 PM
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 (https://github.com/MaddTheSane/SVGImageRep), for those curious.



xStep
Mar 25, 2012, 05:14 PM
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.


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

Madd the Sane
Mar 25, 2012, 06:47 PM
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.

xStep
Mar 26, 2012, 01:00 AM
Have you solved your problem?

Madd the Sane
Mar 26, 2012, 01:41 PM
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.

xStep
Mar 26, 2012, 02:55 PM
Read the very first sentence in my first response. When you comprehend that, act on it.

Madd the Sane
Mar 26, 2012, 03:27 PM
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
Mar 26, 2012, 08:02 PM
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
Mar 26, 2012, 08:31 PM
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
Mar 27, 2012, 01:46 PM
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.

xStep
Mar 27, 2012, 02:50 PM
Frankly, I'd question why the change worked.