iPad模拟器中的奇怪崩溃(< = 4.3)(EXC_BAD_ACCESS) - 任何想法?

时间:2011-10-24 09:06:21

标签: objective-c ipad exc-bad-access simulator

偶尔我只会在模拟器中遇到一个非常奇怪的崩溃(< = 4.3)。当我按下嵌入弹出窗口的导航控制器上的按钮时会发生这种情况。在popover下有一个EAGLView渲染的东西。内存处理正确,等等......在设备上没有任何问题。

有什么想法吗?

这是一个调用堆栈:

* thread #1: tid = 0x2c03, 0x00ab6707 CoreGraphics`CGColorGetAlpha + 17, stop reason = EXC_BAD_ACCESS (code=1, address=0x1cc9b72c)
frame #0: 0x00ab6707 CoreGraphics`CGColorGetAlpha + 17
frame #1: 0x00dc9871 QuartzCore`-[CALayer _renderBackgroundInContext:] + 97
frame #2: 0x00dc97af QuartzCore`-[CALayer renderInContext:] + 977
frame #3: 0x00dcf15c QuartzCore`-[CALayer _renderSublayersInContext:] + 444
frame #4: 0x00dc97e1 QuartzCore`-[CALayer renderInContext:] + 1027
frame #5: 0x00dcf15c QuartzCore`-[CALayer _renderSublayersInContext:] + 444
frame #6: 0x00dc97e1 QuartzCore`-[CALayer renderInContext:] + 1027
frame #7: 0x003434a9 UIKit`-[UIView(Internal) _renderSnapshotWithRect:inContext:] + 790
frame #8: 0x0067776d UIKit`-[UIClipCornerView _updateSnapshot] + 697
frame #9: 0x0067723c UIKit`-[UIRoundedCornerView didMoveToSuperview] + 51
frame #10: 0x0033c750 UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1080
frame #11: 0x0033aaa3 UIKit`-[UIView(Hierarchy) addSubview:] + 57
frame #12: 0x004df1ad UIKit`-[UILayoutContainerView _beginFastMode] + 259
frame #13: 0x003c0c74 UIKit`-[UIViewController(UINavigationControllerItem) setEditing:animated:] + 249
frame #14: 0x0051453b UIKit`-[UITableViewController setEditing:animated:] + 73
frame #15: 0x003b6d1e UIKit`-[UIViewController(UINavigationControllerItem) _toggleEditing:] + 77
frame #16: 0x0030b4fd UIKit`-[UIApplication sendAction:to:from:forEvent:] + 119
frame #17: 0x0051dcc3 UIKit`-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
frame #18: 0x0030b4fd UIKit`-[UIApplication sendAction:to:from:forEvent:] + 119
frame #19: 0x0039b799 UIKit`-[UIControl sendAction:to:forEvent:] + 67
frame #20: 0x0039dc2b UIKit`-[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
frame #21: 0x0039c7d8 UIKit`-[UIControl touchesEnded:withEvent:] + 458
frame #22: 0x0032fded UIKit`-[UIWindow _sendTouchesForEvent:] + 567
frame #23: 0x00310c37 UIKit`-[UIApplication sendEvent:] + 447
frame #24: 0x00315f2e UIKit`_UIApplicationHandleEvent + 7576
frame #25: 0x018f0992 GraphicsServices`PurpleEventCallback + 1550
frame #26: 0x00f79944 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
frame #27: 0x00ed9cf7 CoreFoundation`__CFRunLoopDoSource1 + 215
frame #28: 0x00ed6f83 CoreFoundation`__CFRunLoopRun + 979
frame #29: 0x00ed6840 CoreFoundation`CFRunLoopRunSpecific + 208
frame #30: 0x00ed6761 CoreFoundation`CFRunLoopRunInMode + 97
frame #31: 0x018ef1c4 GraphicsServices`GSEventRunModal + 217
frame #32: 0x018ef289 GraphicsServices`GSEventRun + 115
frame #33: 0x00319c93 UIKit`UIApplicationMain + 1160

还有一件事似乎很重要:当底层的EAGLView被隐藏时,它就不会发生。 GLView和Popover不共享任何数据 - 有趣,不是吗?我怀疑当按下按钮(“编辑”)想要重绘/切换到“蓝色”时会发生一些混合,因为弹出标题是一种半透明的。对我来说听起来像是模拟器问题;谁有这样的东西?

感谢您的回答,

WL

2 个答案:

答案 0 :(得分:2)

在调试器中设置NSZombieEnabledMallocStackLoggingguard malloc。然后,当您的应用程序崩溃时,请在gdb控制台中输入:

(gdb) info malloc-history 0x543216

0x543216替换为导致崩溃的对象的地址(可能来自此行:* thread #1: tid = 0x2c03, 0x00ab6707 CoreGraphics CGColorGetAlpha + 17, stop reason = EXC_BAD_ACCESS (code=1, address=0x1cc9b72c)),您将获得更有用的堆栈跟踪,它可以帮助您精确定位确切的行在您的代码中导致问题。

See this article for more detailed instructions.

答案 1 :(得分:0)

GDB给了我类似的东西:

    Alloc: Block address: 0x12387ff0 length: 16
    Stack - pthread: 0xa0014540 number of frames: 38
        0: 0x5fb8e in GMmalloc_zone_malloc_internal
        1: 0x5fd31 in GMmalloc_zone_malloc
        2: 0x60327 in GMmalloc_zone_calloc
        3: 0x60375 in GMcalloc
        4: 0x132a2d4 in class_createInstance
        5: 0xec65d8 in +[NSObject(NSObject) allocWithZone:]
        6: 0x48218e in +[UIColor allocWithZone:]
        7: 0xec63da in +[NSObject(NSObject) alloc]
        8: 0x4812c6 in +[UIColor clearColor]
        9: 0x15b1d in -[EAGLView initWithCoder:]

我们可以看到EAGLView参与......

...事实上经过一些挖掘后我发现问题与EAGLLayer背景颜色有关。我宣布如下:

    eaglLayer.backgroundColor = (CGColorRef) [UIColor clearColor];

在此之前,这通常很好。

我修复了:

    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    const CGFloat clearColor[] = {0.0, 0.0, 0.0, 0.0};
    eaglLayer.backgroundColor = CGColorCreate(rgb, clearColor);
    CGColorSpaceRelease(rgb); 

或更短:

    eaglLayer.backgroundColor = [UIColor clearColor].CGColor;

此后没有异常。

@ chown:谢谢你的提示。

WL