0

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];

                                                }

                                            }

                                        }];
Community
  • 1
  • 1
Jacob
  • 2,338
  • 2
  • 22
  • 39
  • po [NSThread isMainThread] in console. If 0 then schedule alery view on main thread. Meh. – pronebird Mar 08 '15 at 16:43
  • @Andy as I stated in the question, I tried scheduling it on the main thread and the app still crashes. – Jacob Mar 08 '15 at 16:44
  • @Andy When I log that it says that it is on the main thread. – Jacob Mar 09 '15 at 03:46
  • I have this exact same code in a different view controller and it works perfectly, it is just this tableview that crashes. – Jacob Mar 09 '15 at 03:46
  • Could you try using UIView#snapshotViewAfterScreenUpdates instead of CALayer#renderInContext? I think UIView's method is more safe. – pronebird Mar 09 '15 at 12:30

0 Answers0