I am trying to display an SCLAlertView in my app, but I am getting this error:
Thread 1: EXC_BAD_ACCESS (code=EXC_1386_GPFLT)
on this line [keyWindow.layer renderInContext:context];
I am creating the alert after I call one of my parse cloud code functions. I have read that renderInContext should not be called in a background thread, but I have this exact same code in a different view controller (also after I call a cloud code function), and the alert displays perfectly.
Also, if I display and hide a regular UIAlertView immediately before I show this one, the SCLAlertView shows without a problem, but the view behind it is a solid white. Why is this happening? Is UIAlertView somehow breaking out of the background thread?
I have tried displaying the SCLAlertView in a background thread as suggested here: objective c renderInContext crash on background thread but the app still crashed.
Here is my code to display the alert:
[PFCloud callFunctionInBackground:@"canWeStart"
withParameters:@{@"inviteId": self.selectedObject.objectId,
@"gameType": [[self.selectedObject objectForKey:@"GameType"] objectForKey:@"type"]}
block:^(NSArray *startStuff, NSError *error) {
if (!error) {
NSNumber *canStart = startStuff[0];
BOOL startBool = [canStart boolValue];
if(startBool)
{
//Stuff
}
else
{
//If I show this first, my alert shows perfectly.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Others" message:@"Need to accept" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert dismissWithClickedButtonIndex:0 animated:NO];
SCLAlertView *alert =
[[SCLAlertView alloc] init];
alert.backgroundType = Blur;
//button.layer.borderWidth = 2.0f;
[alert setTitleFontFamily:@"Alba" withSize:18.0f];
[alert setBodyTextFontFamily:@"Arista 2.0" withSize:14.0f];
[alert setButtonsTextFontFamily:@"Arista 2.0 Light" withSize:14.0f];
alert.customViewColor = [UIColor pxColorWithHexValue:@"2b3355"];
alert.backgroundViewColor = [UIColor whiteColor];
[alert showNotice:self.navigationController title:@"Invite Accepted" subTitle:@"Others still need to accept the invite, then the game will begin!" closeButtonTitle:@"Ok" duration:0.0f];
}
}
}];