Hi

I wrote a Quark XTension that dynamically generates ad placeholder images on a 
page and am having a problem where doing a restore on a saved NSGraphicsContext 
crashes after the last ad is placed. If I comment out the save/restore context, 
the app doesn't crash but it also doesn't render the text parts of the 
placeholder image. The exact code worked fine for months but It appears that 
something I did outside of these functions had a ripple effect that causes 
save/restore to fail. I've been futzing with this for two days and don't seem 
to be any closer to solving it. Here's the gdb trace of the crash. Anyone shed 
any light on why this might be happening?

Thanks in advance

#0  0x9001a6e8 in objc_msgSend ()
#1  0x9568434d in +[NSGraphicsContext setCurrentContext:] ()
#2  0x9562a4c2 in -[NSCachedImageRep dealloc] ()
#3  0x9562a25d in -[NSImage _freeRepresentation:] ()
#4  0x9562a064 in -[NSImage dealloc] ()
#5  0x916ff7bf in NSPopAutoreleasePool ()
#6  0x95c0f02e in carbonAppWindowMouseHandler ()
#7  0x958f9ec9 in carbonAppWindowHandler ()
#8  0x90960763 in DispatchEventToHandlers ()
#9  0x9095fb9d in SendEventToEventTargetInternal ()
#10 0x9097c4ee in SendEventToEventTarget ()
#11 0x9098eb90 in ToolboxEventDispatcherHandler ()
#12 0x90960b1c in DispatchEventToHandlers ()
#13 0x9095fb9d in SendEventToEventTargetInternal ()
#14 0x9097c4ee in SendEventToEventTarget ()
#15 0x909e9504 in ToolboxEventDispatcher ()
#16 0x909e5d5e in RunApplicationEventLoop ()
#17 0x0018b089 in main ()
#18 0x0000236e in _start ()
#19 0x00002295 in start ()

Here's the method containing the NSGraphicsContext save restore

(NOTE: The trace seems to indicate that the problem begins at the 
"[NSGraphicsContext setCurrentContext: nsContext];" line near the end of the 
method)

- (void) drawImageTextInCGContext:(CGContextRef) inContextRef
{
        NSRect                                          selfFrame               
= [self adFrame],
                                                                textRect;
        
        NSString                                        *tempSlug               
= ([slug length] == 0)                  ? nil : [slug stringByAppendingString: 
@"\r"],
                                                                *tempClient     
        = ([client length] == 0)                ? nil : [client 
stringByAppendingString: @"\r"],
                                                                *tempTeaser     
        = (([teaser length] == 0) || [teaser isEqualToString: @"L"]) ? nil : 
[teaser stringByAppendingString: @"\r"],
                                                                *tempDimensions 
= ([dimensions length] == 0)    ? nil : dimensions;
                                                
        NSSize                                          attrSize;
                                                
        NSMutableAttributedString   *result                     = 
[[NSMutableAttributedString alloc] init];
        
        NSAttributedString                      *adjSlug                = [self 
styledString: tempSlug style: [PMStyles adHeadlineStyle]],
                                                                *adjClient      
        = [self styledString: tempClient style: [PMStyles adBodyStyle]],
                                                                *adjTease       
        = [self styledString: tempTeaser style: [PMStyles adBodyStyle]],
                                                                *adjDim         
        = [self styledString: tempDimensions style: [PMStyles adBodyStyle]];
        
        NSRange                                         alignRange;
        
        NSGraphicsContext                       *nsContext              = 
[NSGraphicsContext graphicsContextWithGraphicsPort: inContextRef flipped: NO];
        
        if (adjSlug != nil)
                [result appendAttributedString: adjSlug];
                
        if (adjClient != nil)
                [result appendAttributedString: adjClient];
        
        if (adjTease != nil)
                [result appendAttributedString: adjTease];
                
        if (adjDim != nil)
                [result appendAttributedString: adjDim];
        
        alignRange.location = 0;
        alignRange.length   = [result length];
        
        [result setAlignment: NSCenterTextAlignment range: alignRange];
                        
        attrSize = [result size];
        
        attrSize.height = (attrSize.height > selfFrame.size.height) ? 
selfFrame.size.height : attrSize.height ;
        
        textRect.size           = attrSize;
        textRect.origin.x       = (selfFrame.size.width - attrSize.width) / 2;
        textRect.origin.y       = (selfFrame.size.height - attrSize.height) / 2;
        
        // draw text into nsContext
        NSLog(@"drawing text to context: %@", nsContext);
        
        // 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];
        [nsContext saveGraphicsState];
        
        [[PMColors blackColor] set];
        [result drawInRect: textRect];
        
        //[nsContext restoreGraphicsState];
}

_______________________________________________

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