2

Today, I upgrade my Xcode to the latest version(Version 5.1 (5B130a)) to support iOS 7.1. After doing this, I run my project in Xcode as usually. Then app crashes. I didn't change any code before upgrading the SDK version. The code is running perfectly in iOS 5.x, 6.x, 7.0.x.

I am simply presenting another view controller in the current view controller. they are both initialized by storyboard. While processing presentViewController method, it gets a error message "Thread 1: EXC_BAD_ACCESS (code=2, address=0x60)". I have checked the variables, they are both alive, not a released garbage. What's the problem with iOS 7.1??

the project is using non-ARC mechanism. Here is my code:

@property (nonatomic, retain) ArticleViewController *articleView;
....

self.articleView = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"ArticleViewController"];
...

[self presentViewController:self.articleView animated:NO completion:^() {
    log(@"has shown article page...");
}];

but it works fine if presenting another view by using addSubView function:

[self.view addSubView:self.articleView.view];

I really don't know why this happens.

firestoke
  • 1,051
  • 11
  • 23

4 Answers4

3

This happened to my app while presenting a view controller with modalPresentationStyle = UIModalPresentationCustom;

Here's how my code looks like on iOS 7.0:

//Inside my MyPresentedViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setupContent];
    }
    return self;
}

- (void)setupContent
{
    //TransitionManager adopts UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning
    TransitionManager *transitionManager = [[TransitionManager alloc] init];
    transitionManager.presenting = YES;

    self.modalPresentationStyle = UIModalPresentationCustom;
    self.transitioningDelegate = transitionManager;
}

However, the above code crashes on iOS 7.1 so I changed the implementation to:

@interface MyPresentedViewController

@property (nonatomic, strong) TransitionManager *transitionManager;

@end

...

//Inside my MyPresentedViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setupContent];
    }
    return self;
}

- (void)setupContent
{
    //TransitionManager adopts UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning
    self.transitionManager = [[TransitionManager alloc] init];
    _transitionManager.presenting = YES;

    self.modalPresentationStyle = UIModalPresentationCustom;
    self.transitioningDelegate = _transitionManager;
}

Basically, instead of declaring a transitionManager object inside the setupContent method, I created a private property (strong reference) for it.

yoninja
  • 1,952
  • 2
  • 31
  • 39
0

Hm the only thing I can think of is ensuring that your articleView property is a strong reference.

@property (nonatomic, strong) ArticleViewController *articleView;
Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
Tim Sawtell
  • 307
  • 2
  • 7
  • forget to say, the project is using non-ARC mechanism. so, the property is declared with retain instead of strong. @property (nonatomic, retain) ArticleViewController *articleView; whatever, I have tried to modify it to strong, app still crash though. – firestoke Mar 14 '14 at 02:44
0

I ran into a similar issue with a picker view. In my case the pickerview was set to nil after the selection handler block, although this caused no issues as recently as last night, it was causing the app to crash this morning. Removing that line fixed the issue, however I have converted this project to ARC in the last month so you may have to find a better way to handle clean up.

Schuuure
  • 301
  • 2
  • 10
0

This may be completely unrelated to the stated problem or answers but I ran into a similar problem when accessing an NSString on an iPhone 5S. The exact same code runs fine on an iPad and iPad at the same time.

To start out with I think it's important to state that I'm running under ARC, and I have been told repeated not to "release" any objects I instantiate in my functions. I've had problems with this before so I use some of my C# background to set almost all of my local variables to nil (null in C#). Yes, I don't trust MS GC either.

Back to the problem at hand; I have an NSString called 'data'. 'data' is read as a result from another method in a different class. Using NSLog I can see the contents of 'data'. On the next line I convert 'data' to an array to use it in scanf. That still works. On the third line I try to NSLog 'data' again, but then I get the EXC_BAD_ACCESS error. Each time it has a different address. I'm even less comfortable with ARC than I am with the Microsoft Garbage Collector so I wrapped the function in a try..catch..finally. 'data' is now sitting outside of the try..catch..finally. I'm setting 'data' to nil in the finally, which seems to fix the problem.

I know this was a bit long winded, but I would really appreciate it someone could explain why this would happen. I'm expecting to see a lot of these problems to popup all over my code now.

DJ van Wyk
  • 531
  • 1
  • 13
  • 23