0

My app crashes randomly when navigating back in a NavigationController. Here is what I know:

  • It happens randomly (sometimes, I can come back once or twice and if I reload the viewController and press "back" again it will crash)
  • It happens even with an empty ViewController (I tried to comment out all my code in ViewController.h and .m and to remove all the outlets links)
  • Nothing shows up in the debug console, only a EXEC_BAD_ACCESS is shown in main.m

I spent the afternoon on this and tried everything.
I don't include code right now because I have no idea where to look. As I said, it even happens with an empty ViewController.

Any thoughts or similar experience ?

EDIT:

  • Yes I tried to add an exception breakpoint
  • I even tried to find some observer issues with Spark debugger.

EDIT 2: Actually, the ViewControllers were not that empty. The import on an UIView category was the problem. Check my answer below.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
  • Adding an [Exception Breakpoint](http://stackoverflow.com/a/17802723/653513) could help narrowing things up. – Rok Jarc May 29 '15 at 16:41
  • _I don't include code right now because I have no idea where to look._ Start with the code for popping and pushing views to the stack. Can you show us the code that's called when you go to a new view? – BSMP May 29 '15 at 16:41
  • EXEC_BAD_ACCESS usually happens when you try to access an object that is not instantiated or has been released. Check if all the objects are retained in the previous view. – Dino Tw May 29 '15 at 16:45
  • See http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – rmaddy May 29 '15 at 16:55
  • How are you navigating? Segues (if yes what type?), pushing/poping view controllers? – sunshinejr May 29 '15 at 17:56
  • Thanks for your time. @rokjarc Already tried, no exception are thrown. – Quentin Hayot May 29 '15 at 18:47
  • @BSMP nothing special, I'm litteraly doing performSegueWithIdentifier: nothing else. – Quentin Hayot May 29 '15 at 18:48
  • @rmaddy iOS is my domain of expertise. But this stuff nothing happened before. I know how to debug, but here nothing works. – Quentin Hayot May 29 '15 at 18:50
  • @sunshine Yes, segue with a standard "show" type. And then the back action is called by the back button of the navigation controller – Quentin Hayot May 29 '15 at 18:50
  • Try turning on slow animations in the simulator, to see if it causes the problem to occur more regularly. View controllers that are updated during a navigation animation (due to a timer or some other asynchronous event) can cause crashes as the view outlives it's controller. – Darren May 30 '15 at 01:34

2 Answers2

1

It's difficult to say exactly what could be causing it without more information, but in my experience the most common reason for an EXC_BAD_ACCESS is when someone tries to call a selector on a deallocated instance. This issue can be a lot easier to debug if you enable zombie objects.

Edit Scheme -> Diagnostics -> Enable Zombie Objects

Now instead of getting a bad access exception you should get a more helpful "message sent to deallocated instance" error (assuming that's actually the problem), along with what method was being called on which class of object.

Ryan McLeod
  • 596
  • 1
  • 3
  • 8
  • I tried that on Friday without result. But to day I got "Message sent to deallocated instance" error. A quick search got me to this answer: http://stackoverflow.com/a/17367251/598812 wich was exactly my problem. Thanks ! – Quentin Hayot Jun 01 '15 at 08:15
0

The problem was that some of my views were importing a custom UIView category that included a dealloc method. I deleted the dealloc method from the category and everything is fine now.

Quentin Hayot
  • 7,786
  • 6
  • 45
  • 62
  • Was that your own category or some third party code? If it is third party code, tell us which one so that it is avoided. – gnasher729 Jun 01 '15 at 08:27