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

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #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. thread starter macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
  5. thread starter macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #6
    Read the very first sentence in my first response. When you comprehend that, act on it.
     
  7. thread starter macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #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. thread starter macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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. thread starter macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #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

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.

Share This Page