1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Resolved [NSGraphicsContext graphicsPort] returning null

Discussion in 'Mac Programming' started by Madd the Sane, Mar 25, 2012.

  1. Madd the Sane, Mar 25, 2012
    Last edited: Mar 27, 2012

    macrumors 6502

    Madd the Sane

    #1
    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.
     
  2. macrumors 68000

    #2
    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];
    
     
  3. macrumors 6502

    Madd the Sane

    #3
    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.
     
  4. macrumors 68000

    #4
    Have you solved your problem?
     
  5. macrumors 6502

    Madd the Sane

    #5
    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.
     
  6. macrumors 68000

    #6
    Read the very first sentence in my first response. When you comprehend that, act on it.
     
  7. macrumors 6502

    Madd the Sane

    #7
    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.
     
  8. macrumors 68000

    #8
    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.
     
  9. macrumors 6502

    Madd the Sane

    #9
    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.
     
  10. macrumors 6502

    Madd the Sane

    #10
    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.
     
  11. macrumors 68000

    #11
    Frankly, I'd question why the change worked.
     

Share This Page