CGContextSetStyle console log error?

  • Hi,

    > From time to time my app generates the following
    console error:

    CGContextSetStyle: invalid context

    Does anybody know what this means or what it indicates
    I am doing wrong? An internet and archive search
    reveals nothing, and there is nothing about
    "CGContextSetStyle" in the docs. Moreover, I do
    nothing with CGContext at all in my code. My app
    includes the Quartz framework only for use of the
    PDFView.

    In fact, the only thing I can think of that has
    anything to do with a graphics context in my code are
    these lines in a custom view, in its -drawRect:
    method:

    NSRect patternFrame = [self convertRect:[self frame]
    toView:nil];
    [[NSGraphicsContext currentContext]
    setPatternPhase:NSMakePoint(patternFrame.origin.x,NSMaxY(patternFrame))];

    I use the above just so that the background colour, if
    it uses -colorWithPatternImage:, gets drawn with its
    origin in the top-left of the view, otherwise it looks
    very odd when scrolling. I have no idea if the above
    method could have anything to do with this console
    error, but it seems to be the only place I do anything
    with a context...

    If anyone has any ideas what might be causing this, I
    would be very grateful.

    All the best,
    Keith


    ____________________________________________________________________________________
    Yahoo! oneSearch: Finally, mobile search
    that gives answers, not web links.
    http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
  • On Aug 24, 2007, at 1:29 AM, Keith Blount wrote:

    > From time to time my app generates the following console error:
    >
    > CGContextSetStyle: invalid context
    >
    > Does anybody know what this means or what it indicates I am doing
    > wrong? An internet and archive search reveals nothing, and there is
    > nothing about "CGContextSetStyle" in the docs. Moreover, I do
    > nothing with CGContext at all in my code. My app
    > includes the Quartz framework only for use of the PDFView.

    CGContextSetStyle is likely an internal Quartz function called by
    some other code, but in any case the console message suggests that an
    invalid CGContextRef is being passed to it from someplace farther
    back in the call chain. The most likely place would be in your code
    where you won't see any CGContextFoo() calls since they're wrapped by
    Cocoa methods.

    > In fact, the only thing I can think of that has anything to do with
    > a graphics context in my code are these lines in a custom view, in
    > its -drawRect: method:
    >
    > NSRect patternFrame = [self convertRect:[self frame] toView:nil];
    > [[NSGraphicsContext currentContext] setPatternPhase: NSMakePoint
    > (patternFrame.origin.x, NSMaxY(patternFrame))];
    >
    > I use the above just so that the background colour, if it uses -
    > colorWithPatternImage:, gets drawn with its origin in the top-left
    > of the view, otherwise it looks very odd when scrolling. I have no
    > idea if the above method could have anything to do with this
    > console error, but it seems to be the only place I do anything with
    > a context...

    If that's the only place where you're drawing, you could always add
    NSLog(...) calls to the beginning and end of your -drawRect: method
    to see if they bracket the console method you're seeing above.

    steve
  • Thanks for your reply, Steve - much appreciated.
    NSLog() is my usual (and usually most effective) way
    of debugging things like this, but in this case the
    CGContextSetStyle log message seems so sporadic that I
    could be waiting a long time for it to reappear; I was
    hoping there might be some clear-cut situation that
    would cause this message, but I guess not - so I'll go
    ahead and follow your advice, and hope it crops up
    again soon.

    If anyone does have any further ideas, of course, I
    would be very grateful.

    Thanks again and all the best,
    Keith

    --- <cocoa-dev-request...> wrote:
    >
    >> From time to time my app generates the following
    > console error:
    >>
    >> CGContextSetStyle: invalid context
    >>
    >> Does anybody know what this means or what it
    > indicates I am doing
    >> wrong? An internet and archive search reveals
    > nothing, and there is
    >> nothing about "CGContextSetStyle" in the docs.
    > Moreover, I do
    >> nothing with CGContext at all in my code. My app
    >> includes the Quartz framework only for use of the
    > PDFView.
    >
    > CGContextSetStyle is likely an internal Quartz
    > function called by
    > some other code, but in any case the console message
    > suggests that an
    > invalid CGContextRef is being passed to it from
    > someplace farther
    > back in the call chain. The most likely place would
    > be in your code
    > where you won't see any CGContextFoo() calls since
    > they're wrapped by
    > Cocoa methods.
    >
    >> In fact, the only thing I can think of that has
    > anything to do with
    >> a graphics context in my code are these lines in a
    > custom view, in
    >> its -drawRect: method:
    >>
    >> NSRect patternFrame = [self convertRect:[self
    > frame] toView:nil];
    >> [[NSGraphicsContext currentContext]
    > setPatternPhase: NSMakePoint
    >> (patternFrame.origin.x, NSMaxY(patternFrame))];
    >>
    >> I use the above just so that the background
    > colour, if it uses -
    >> colorWithPatternImage:, gets drawn with its origin
    > in the top-left
    >> of the view, otherwise it looks very odd when
    > scrolling. I have no
    >> idea if the above method could have anything to do
    > with this
    >> console error, but it seems to be the only place I
    > do anything with
    >> a context...
    >
    > If that's the only place where you're drawing, you
    > could always add
    > NSLog(...) calls to the beginning and end of your
    > -drawRect: method
    > to see if they bracket the console method you're
    > seeing above.
    >
    > steve
    >


    ____________________________________________________________________________________
    Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
    http://smallbusiness.yahoo.com/webhosting
  • On Aug 24, 2007, at 10:29 AM, Keith Blount wrote:

    > Hi,
    >
    >> From time to time my app generates the following
    > console error:
    >
    > CGContextSetStyle: invalid context
    >
    > Does anybody know what this means or what it indicates
    > I am doing wrong? An internet and archive search
    > reveals nothing, and there is nothing about
    > "CGContextSetStyle" in the docs. Moreover, I do
    > nothing with CGContext at all in my code. My app
    > includes the Quartz framework only for use of the
    > PDFView.

    I saw similar console errors while running some badly coded unit-tests.
    I called drawRect: directly on a custom view to assure the objects in
    this view get their
    draw-method called. All calls to the graphicsContext emitted those
    "invalid context"
    errors. You can put a breakpoint on the syslog-function (seems to be
    called by
    Quartz error-reporting) to stop where the error message gets logged.

    HTH,

    felix
  • Hi, Felix,

    Pardon me if I'm wrong, but rather than calling -drawRect: directly,
    couldn't you call -display or -displayIfNeeded (or even -
    displayIfNeededIgnoringOpacity) in order to force the redrawing of
    your view?

    Cheers,
    Andrew

    On Aug 27, 2007, at 7:03 AM, Felix Franz wrote:

    > On Aug 24, 2007, at 10:29 AM, Keith Blount wrote:
    >
    >> Hi,
    >>
    >>> From time to time my app generates the following
    >> console error:
    >>
    >> CGContextSetStyle: invalid context
    >>
    >> Does anybody know what this means or what it indicates
    >> I am doing wrong? An internet and archive search
    >> reveals nothing, and there is nothing about
    >> "CGContextSetStyle" in the docs. Moreover, I do
    >> nothing with CGContext at all in my code. My app
    >> includes the Quartz framework only for use of the
    >> PDFView.
    >
    > I saw similar console errors while running some badly coded unit-
    > tests.
    > I called drawRect: directly on a custom view to assure the objects
    > in this view get their
    > draw-method called. All calls to the graphicsContext emitted those
    > "invalid context"
    > errors. You can put a breakpoint on the syslog-function (seems to
    > be called by
    > Quartz error-reporting) to stop where the error message gets logged.
    >
    > HTH,
    >
    > felix
  • On Aug 27, 2007, at 10:49 AM, Andrew Merenbach wrote:

    > Hi, Felix,
    >
    > Pardon me if I'm wrong, but rather than calling -drawRect: directly,
    > couldn't you call -display or -displayIfNeeded (or even -
    > displayIfNeededIgnoringOpacity) in order to force the redrawing of
    > your view?

    More than  "couldn't you" I would say "shouldn't you".  The answer of
    course is "Yes, you should".  Although you really shouldn't call any
    of these directly unless you have VERY specific needs.  You should be
    using one of the "setNeedsDisplay" variants.

    But the person that posted that did say they were badly coded unit
    tests :-)

    Scott
  • Thanks the replies.

    Unfortunately (or fortunately :) ) I don't do anything
    like call -drawRect: directly from anywhere...

    I did realise that my original post wasn't entirely
    correct - whilst I only call -currentContext in my
    NSView subclass to set the patternImage origin, I use
    Andreas Meyer's NSBezier categories for gradient fills
    (NSBezierPath_AMGradient) which also has calls to
    -currentContext and does some Quartz stuff.

    I followed the original poster's suggestion of putting
    NSLogs around all the calls to -currentContext and the
    Quartz-related methods so that I could narrow down
    where these errors are coming from, but wouldn't you
    know that in the past several days I haven't seen
    these errors at all, despite using the app
    intensively. As I said before, the error seems very
    erratic (fortunately it has no effect on the running
    of the program anyway). Though I did get another CG
    error when switching between screens, when the window
    of my app - which was being used on a 24" external
    display - was now bigger than my MacBook Pro's 15"
    display. Odd.

    Anyway, as before, if anyone has any more insights
    into what could be causing this - especially given
    that right now I'm just waiting for the error to
    appear again - I would be very grateful.

    Thanks again and all the best,
    Keith

    --- Felix Franz <franz...> wrote:

    > On Aug 24, 2007, at 10:29 AM, Keith Blount wrote:
    >
    >> Hi,
    >>
    >>> From time to time my app generates the following
    >> console error:
    >>
    >> CGContextSetStyle: invalid context
    >>
    >> Does anybody know what this means or what it
    > indicates
    >> I am doing wrong? An internet and archive search
    >> reveals nothing, and there is nothing about
    >> "CGContextSetStyle" in the docs. Moreover, I do
    >> nothing with CGContext at all in my code. My app
    >> includes the Quartz framework only for use of the
    >> PDFView.
    >
    > I saw similar console errors while running some
    > badly coded unit-tests.
    > I called drawRect: directly on a custom view to
    > assure the objects in
    > this view get their
    > draw-method called. All calls to the graphicsContext
    > emitted those
    > "invalid context"
    > errors. You can put a breakpoint on the
    > syslog-function (seems to be
    > called by
    > Quartz error-reporting) to stop where the error
    > message gets logged.
    >
    > HTH,
    >
    > felix
    >
    >


    ____________________________________________________________________________________
    Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
    http://sims.yahoo.com/
  • On 24.08.2007, at 10:29, Keith Blount wrote:
    > Moreover, I do
    > nothing with CGContext at all in my code. My app
    > includes the Quartz framework only for use of the
    > PDFView.

      Have you checked you're actually adding all frameworks to your
    project that you need? With ZeroLink on, missing frameworks can get
    "half-loaded" if some OS code loads one of their sub-frameworks, and
    thus you might see weird behaviour. Try doing a release build, and
    see if you get any missing frameworks there.

      More likely, you're screwing up some graphics state. Are you doing
    any threading? Are you perhaps handing a CGContext/NSGraphicsContext
    pointer off to another thread? Are you calling AppKit methods from
    anything else than the main thread that directly do drawing? Have you
    checked for double-releases and other errors that may result in
    memory smashers? Are you doing *anything* with drawing on that same
    window, or are you doing something special like redirecting drawing
    intended for one place to another?

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • Thanks for your reply, Uli.

    The frameworks are definitely all getting loaded and
    I'm not using ZeroLink - users are occasionally seeing
    this error message on the Console in the release
    version.

    Also, I'm not doing anything particular fancy with
    threads - my app is pretty much single-threaded.
    Certainly there are no extra threads concerned with
    any of my (very few calls to the current graphics
    context.

    It doesn't seem to be memory related because there is
    no crash or hang. In all cases where this error has
    appeared it has seemed benign - it appears in the log
    but has no effect over the running of the program.

    Thanks again for your reply.
    All the best,
    Keith

    --- Uli Kusterer <witness.of.teachtext...> wrote:

    > On 24.08.2007, at 10:29, Keith Blount wrote:
    >> Moreover, I do
    >> nothing with CGContext at all in my code. My app
    >> includes the Quartz framework only for use of the
    >> PDFView.
    >
    > Have you checked you're actually adding all
    > frameworks to your
    > project that you need? With ZeroLink on, missing
    > frameworks can get
    > "half-loaded" if some OS code loads one of their
    > sub-frameworks, and
    > thus you might see weird behaviour. Try doing a
    > release build, and
    > see if you get any missing frameworks there.
    >
    > More likely, you're screwing up some graphics
    > state. Are you doing
    > any threading? Are you perhaps handing a
    > CGContext/NSGraphicsContext
    > pointer off to another thread? Are you calling
    > AppKit methods from
    > anything else than the main thread that directly do
    > drawing? Have you
    > checked for double-releases and other errors that
    > may result in
    > memory smashers? Are you doing *anything* with
    > drawing on that same
    > window, or are you doing something special like
    > redirecting drawing
    > intended for one place to another?
    >
    > Cheers,
    > -- M. Uli Kusterer
    > http://www.zathras.de
    >
    >
    >
    >

          ____________________________________________________________________________________
    Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
previous month august 2007 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today