-------------- Original message ----------------------
From: [EMAIL PROTECTED]
> 
>  -------------- Original message ----------------------
> From: glenn andreas <[EMAIL PROTECTED]>
> > 
> > You're setting a graphics context:
> > >   // uncommenting the next line works fine for all ads except the  
> > > last which
> > >   // causes a crash after the last ad image is placed.
> > >   //[NSGraphicsContext setCurrentContext: nsContext];
> > 
> > But you're never restoring the original context, and as a result, the  
> > context is autoreleased later (and is still the current context).   
> > saveGraphicsState and restoreGraphicsState only saves and restores the  
> > state of the current context - it doesn't save/restore the current  
> > context...
> 
> If you look a couple of lines down from that one, you'll see 
> 
> [nsContext restoreGraphicsState];
> 
>  It doesn't seem to make any difference when I uncomment that line as the gdb 
> backtrace of the crash is exactly the same.
> 
> Is that "restoreGraphicsState " what you mean?

If it's any help, here's the method that calls "drawImageTextInCGContext." I'm 
trying to take advantage of CGLayers for speed but if there is a simpler way to 
do this that in the ballpark, speed-wise as CGLayer, I'm not married to my 
solution....

- (void) initImageLayer
{
        NSRect                          selfFrame                       = [self 
adFrame];
        
        CGRect                          rect                            = 
CGRectMake(0, 0, selfFrame.size.width, selfFrame.size.height);
        CGContextRef            imageLayerContext       = NULL;
        CFMutableDataRef        consumerDataRef         = 
CFDataCreateMutable(kCFAllocatorDefault, 0);
        CGDataConsumerRef       consumer                        = 
CGDataConsumerCreateWithCFData(consumerDataRef);
        CGContextRef            context                         = 
CGPDFContextCreate(consumer, &rect, NULL);
        
        CGContextSaveGState(context);
        
        imageLayer                      = CGLayerCreateWithContext(context, 
rect.size, NULL);
        imageLayerContext       = CGLayerGetContext(imageLayer);
        
        // draw background in image layer
        CGContextDrawLayerInRect(imageLayerContext, rect, [self 
backgroundLayer]);
        
        // it's far easier to handle styled text in Cocoa so, just for the 
        // ad text, wrap imageLayerContext inside a NSGraphicsContext 
        [self drawImageTextInCGContext: imageLayerContext];
        
        CGContextRestoreGState(context);
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to