views:

154

answers:

2

When I try to crop an image using NSImage's imageFromRect, I get an EXEC_BAD_ACCESS crash about 50% of the time. This is something that runs on startup (triggered in an awakeFromNib), so the environment shouldn't be changing. I am not sure why it crashes one one launch and not another. When I have a breakpoint set before I crop the image I can see the image was loaded from file correctly, and seems to be of the proper dimensions. Any advice?

Here is the stack trace:

#0  0x97bb58c2 in ripc_RemoveEntry
#1  0x97b927b0 in ripc_AcquireImage
#2  0x97b903be in ripc_DrawImage
#3  0x930f9384 in CGContextDrawImage
#4  0x9463159f in __-[NSBitmapImageRep draw]_block_invoke_1
#5  0x9448e74b in __-[NSBitmapImageRep _performBlockUsingBackingCGImage:]_block_invoke_1
#6  0x94365232 in -[NSBitmapImageRep _performBlockUsingBacking:]
#7  0x9448e6b3 in -[NSBitmapImageRep _performBlockUsingBackingCGImage:]
#8  0x9462f87f in -[NSBitmapImageRep draw]
#9  0xb0006a03 in -[NSImage(Crop) imageFromRect:] at ThemeManager.m:325
#10 0xb000820a in -[FrameImages setImage:] at ThemeManager.m:270
#11 0xb0005f21 in -[ThemeManager setImage:forTheme:] at ThemeManager.m:63
#12 0xb0006397 in +[ThemeManager defaultThemeManager] at ThemeManager.m:39
#13 0xb0005b33 in -[SCThemedView layoutContentView] at SCThemedView.m:92
#14 0x9435ebaf in -[NSNibOutletConnector establishConnection]
#15 0x9435d33b in -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:]
#16 0x9435b450 in loadNib
#17 0x9435a848 in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]
#18 0x9435a759 in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:]
#19 0x9435a6a4 in +[NSBundle(NSNibLoading) loadNibNamed:owner:]
#20 0x943574a9 in NSApplicationMain
#21 0x0000256a in start
A: 

Show us how you're loading the image. That crash is usually the result of an object getting freed before you're done with it.

NSResponder
This is a garbage collected app. I am not doing anything weird with the pointer, so it shouldn't be released too soon.
Bridgeyman
A: 

There's no awakeFromNib in the stack trace; Instead, it looks like the crash happens while the nib loader is still in the process of making the connections ([NSNibOutletConnector establishConnection]), which means the drawing environment may not be properly set up yet.

Try moving the ThemeManager setup code (whatever's making the call to [ThemeManager defaultThemeManager]) from SCThemedView's layoutContentView method to SCThemedView's awakeFromNib.

If that doesn't work, try delaying all ThemeManager layout/drawing until after NSApplication's applicationDidFinishLaunching: method is called.

tedge