Unexpected crashes on iOS15 (SIGTRAP)

Good morning.

I'm writing this post because I really need some help in facing this issue.

This bug started happening on iOS15.

I'm using CocoaPods as package manager.

At first this could seem a trivial question, because the error message is really clear:

Unexpectedly found nil while unwrapping an Optional value... but it isn't (below more details).

The terminating reason is always SIGNAL 5 Trace/BPT trap: 5.

All of them report that the offending line is the same, and here's the piece of code that causes the crash:

if isToShowRealTime {
  sessionComputedData = sessionComputedDataPrv
  sessionStatus = session!.sessionStatus // OFFENDING LINE
} else {
  // Other code...
}

Yes, this is an unconditional unwrapping, but I am certainly sure that this variable is not nil, because, (to be short) it has the same lifetime of the presenting view controller. It is set to nil only when the view controller is dismissed (programmatically). So if the view controller is existing also the variable is.

Here are attached some crash reports, but there are many more saying the same thing.

I can't understand why this variable is nil at that time.

Please, could you help me? Many thanks

Accepted Answer

I’m presuming that session is not declare weak.

I think you need to recheck your assumptions here. There doesn’t seem to be anything weird in your crash reports. The app has definitely died trying to unwrap an optional. The only potential wiggle room here is that the symbolication could be pointing you at the wrong line, but that seem unlikely. It’s much more likely that this code is being called before session gets set up or after it’s been set to nil.

What I’d do is add code like this:

if self.session == nil {
    abort()
}
sessionStatus = session!.sessionStatus // OFFENDING LINE

Once you start getting SIGABRT crash reports pointing at that line, you know for sure what the problem is. You can then start working through your logic to see how you got into this state.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unexpected crashes on iOS15 (SIGTRAP)
 
 
Q