1

On the #viewDidAppear of a "ContainerViewControler", posting a UIAccessibilityScreenChangedNotification causes an intermittent crash with an Exception Type: EXC_CRASH (SIGABRT).

-(void)viewDidAppear:(BOOL)animated
{
    UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.childController.collectionView);
}

Have attached a screenshot with the stack trace.

!Exception stack trace

While trying to debug this, on frame 'objc_exception_throw', did get the exception at $r0

(lldb) po $r0 *** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array

While on frame '_UIAXBroadcastMainThread', got one of the cells in the collection view at $r8

(lldb) po $r8
<UICollectionViewCell: 0x15711ae0; baseClass = UICollectionViewCell; frame = (0 0; 320 278); opaque  = NO; gestureRecognizers = <NSArray: 0x15709f90>; layer = <CALayer: 0x157119b0>>

Under the impression that there is a timing issue between when the collectionView on the childController appears and the accessibility notification delivery, but haven't been able to write a test for it.

Asking for a better understanding as to what UIAccessibility expects the NSArray to hold and what's causing the index out of bounds.

That's on
iOS 7
iPhone 4, iPhone 5

Edit
Since the crash was intermittent, swizzled the #objectAtIndex: method to see what the array is expected to hold.

@implementation NSMutableArray (Debug)

- (id)myObjectAtIndex:(NSUInteger)index
{

    return [self myObjectAtIndex:index];
}

+ (void)load {
    NSLog(@"Swizzling method ...");

    Class arrayClass = NSClassFromString(@"__NSArrayM");
    Method originalMethod = class_getInstanceMethod(arrayClass, @selector(objectAtIndex:));
    Method categoryMethod = class_getInstanceMethod(arrayClass, @selector(myObjectAtIndex:));
    method_exchangeImplementations(originalMethod, categoryMethod);
}

@end

It looks like the array holds all the UIView instances that are subviews to the UICollectionViewCell of the collectionView that the notification was posted and have "Accessibility" enabled.

Not sure how UIAccessibility populates that array.

Wondering if it assumes a size equal to every UIView that has "Accessibility" enabled but fails to populate the array based on some condition that depends on the state of these UIView(s) as part of navigating from one view controller to another and the UIAccessibilityScreenChangedNotification.

qnoid
  • 2,346
  • 2
  • 26
  • 45

0 Answers0