Странный сбой только в симуляторе iPad (<= 4.3) (EXC_BAD_ACCESS) — есть идеи?

#objective-c #ipad #exc-bad-access #simulator

#objective-c #iPad #исключение -плохой доступ #тренажёр

Вопрос:

Иногда я получаю действительно странный сбой только в симуляторе (<= 4.3). Это происходит, когда я нажимаю кнопку на контроллере навигации, встроенном во всплывающее окно. Под всплывающим окном есть 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

Комментарии:

1. Пожалуйста, опубликуйте также код, где вы получаете это исключение.

2. @Aleksejs: исключение приходит в «int main(int argc, char * argv[])»

Ответ №1:

Установите NSZombieEnabled, MallocStackLogging и guard 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) ), и вы получите гораздо более полезную трассировку стека, и это должно помочь вам точно определить точную строку в вашем коде, которая вызывает проблему.

Смотрите Эту статью для получения более подробных инструкций.

Комментарии:

1. Я получил следующее из gdb: ‘Alloc: Адрес блока: 0x12387ff0 длина: 16 Stack — pthread: 0xa0014540 количество кадров: 38 0: 0x5fb8e в GMmalloc_zone_malloc_internal 1: 0x5fd31 в GMmalloc_zone_malloc 2: 0x60327 в GMmalloc_zone_calloc 3: 0x60375 в GMcalloc 4: 0x132a2d4 в class_createInstance 5: 0xec65d8 в [NSObject(NSObject) allocWithZone:] 6: 0x48218e в [UIColor allocWithZone:] 7: 0xec63da в [NSObject(NSObject) alloc] 8: 0x4812c6 в [UIColor clearColor] 9: 0x15b1d в — [EAGLView initWithCoder:]’

Ответ №2:

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