Trying to find source of CGGStackRestore assertion failure

I'm writing a document based app. If I try maximize a window, open a popover or trigger the resizing of an attached sheet I get the following error at the end of the animation.


Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file Context/CGGStack.c, line 77.


Of course I understand that you must save the graphics state before restoring it, however I've ensured that every call to NSGraphicsContext.saveGraphicsState() is followed eventually by a matching restore, and I'm pretty certain this is not directly related to my code.


I have no idea how to find the source of this as all I get is the assembly code in the debugger.


I don't know whether I should file a bug or whether I can somehow dig deeper to find the cause of this. Can anyone help?

I fixed it, I was calling NSGraphicsContext.setCurrentContext(context) in a drawLayer method without a save/restore block around it.

Thanks! I made it for your example & it really helped me) Thank you very much


- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
  
    NSGraphicsContext *nsGraphicsContext;
    nsGraphicsContext = [NSGraphicsContext
                         graphicsContextWithGraphicsPort:ctx flipped:YES ];
    [NSGraphicsContext saveGraphicsState];
    [NSGraphicsContext setCurrentContext:nsGraphicsContext];
    [NSGraphicsContext restoreGraphicsState];
}


On layer that crashed


🙂

Trying to find source of CGGStackRestore assertion failure
 
 
Q