Wes Cossick
Wes Cossick

Reputation: 2933

Crashing with error: EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Using Crashlytics, I see that a small subset of my users are crashing with the error EXC_BAD_ACCESS KERN_INVALID_ADDRESS, on the following line:

[[UIApplication sharedApplication].delegate.window.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

I have been unable to reproduce the crash, but is there some way I can safeguard the line or modify it to prevent future crashes? It's designed to completely remove any views/subviews on the screen.

Please let me know if more information is necessary.

Upvotes: 0

Views: 1172

Answers (1)

artud2000
artud2000

Reputation: 544

You can try this solution

if ( [UIApplication sharedApplication].delegate != nil) {
     for (UIView *subView in [UIApplication sharedApplication].delegate.window.subviews) {
         if ([subView respondsToSelector:@selector(removeFromSuperview)]) {
            [subView performSelector:@selector(removeFromSuperview)];
         }
     }
}

Upvotes: 1

Related Questions