NSImage作物崩溃

时间:2010-02-13 00:02:34

标签: objective-c cocoa nsimage

当我尝试使用NSImage的imageFromRect裁剪图像时,大约50%的时间都会出现EXEC_BAD_ACCESS崩溃。这是在启动时运行的(在awakeFromNib中触发),因此环境不应该改变。我不确定为什么它会崩溃一次发射而不是另一次发射。当我在裁剪图像之前设置断点时,我可以看到图像是从文件中正确加载的,并且看起来是正确的尺寸。有什么建议吗?

这是堆栈跟踪:

#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

2 个答案:

答案 0 :(得分:0)

告诉我们您是如何加载图片的。该崩溃通常是在您完成对象之前释放对象的结果。

答案 1 :(得分:0)

堆栈跟踪中没有awakeFromNib;相反,当nib加载器仍在进行连接([NSNibOutletConnector establishConnection])时,看起来崩溃发生,这意味着绘图环境可能尚未正确设置。

尝试从SCThemedView的[ThemeManager defaultThemeManager]方法移动ThemeManager设置代码(调用layoutContentView的任何内容)到SCThemedView的awakeFromNib

如果这不起作用,请尝试延迟所有ThemeManager布局/绘图,直到调用NSApplication的applicationDidFinishLaunching:方法为止。