I have many threads calling the following function by performSeleactoreOnMainThread method:
-(void) showAlert: (NSString *)message{
if ([NSRunLoop currentRunLoop] != [NSRunLoop mainRunLoop]) {
NSLog(@"<< perform in main thread>>");
[self performSelectorOnMainThread:@selector(showAlert:) withObject:message waitUntilDone:NO];
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Info" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
As, in any case, this method will be called only on main thread, I am not getting the reason for EXC_BAD_ACCESS crash on the line:
[alert show]
And this crash comes only sometimes. Please help.
I guess you forgot to add
return;in your code so that your code below the if are also executed no matter it is in main loop or not.a simple fix may be: