App crashes on Activation of Display after Background Audio

How can I find out what the Problem is? Every Time I start Audio and hear it when the iPad/iPhone is turned off and then activate Display of the device after 10-15 Minutes, the App crashes.

Here are the First Lines of the Crash Report:

Hardware Model:      iPad8,12
Process:             VOH-App [16336]
Path:                /private/var/containers/Bundle/Application/5B2CF582-D108-4AA2-B30A-81BA510B7FB6/VOH-App.app/VOH-App
Identifier:          com.voiceofhope.VOH
Version:             7 (1.0)
Code Type:           ARM-64 (Native)
Role:                Non UI
Parent Process:      launchd [1]
Coalition:           com.voiceofhope.VOH [740]


Date/Time:           2021-08-18 22:51:24.0770 +0200
Launch Time:         2021-08-18 22:36:50.4081 +0200
OS Version:          iPhone OS 14.7.1 (18G82)
Release Type:        User
Baseband Version:    2.05.01
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016d2dffb0
VM Region Info: 0x16d2dffb0 is in 0x16d2dc000-0x16d2e0000;  bytes after start: 16304  bytes before end: 79
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      CG raster data           11cad0000-11d814000 [ 13.3M] r--/r-- SM=COW  
      GAP OF 0x4fac8000 BYTES
--->  STACK GUARD              16d2dc000-16d2e0000 [   16K] ---/rwx SM=NUL  ... for thread 0
      Stack                    16d2e0000-16d3dc000 [ 1008K] rw-/rwx SM=PRV  thread 0

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [16336]
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libswiftCore.dylib            	0x00000001a8028360 swift::MetadataCacheKey::operator==+ 3773280 (swift::MetadataCacheKey) const + 4
1   libswiftCore.dylib            	0x00000001a801ab8c _swift_getGenericMetadata+ 3718028 (swift::MetadataRequest, void const* const*, swift::TargetTypeContextDescriptor<swift::InProcess> const*) + 304
2   libswiftCore.dylib            	0x00000001a7ffbd00 __swift_instantiateCanonicalPrespecializedGenericMetadata + 36

Here is a full crash Report:

Post not yet marked as solved Up vote post of SamDerksen Down vote post of SamDerksen
337 views

Answers

I'm having the same issue without having solved it yet. In my case I'm performing different background tasks (without audio interactions).

Did you use any animations in your SwiftUI views?

  • I use several times withAnimation {}

  • I have noticed that I have a lot of Leaks too. Maybe it has something to do with it

Add a Comment

I seem to have the exact issue as above mentioned. In my case, I play audio in the background also as a notification, and use animations as well. What I was able to determine until now:

  • it only happens when the app is in the background
  • it has to do with audio

what I still don't know:

  • dose it have anything to do with animations, as it is mentioned in the error itself?
  • dose the app crash immediately as the error occurs, or the moment the app returns in the foreground.

The Problem was a Timer in which some Actions with an Animation were executed. I solved the Problem by checking at the beginning of the timer, if the app is Active:


.onReceive(NotificationCenter.default.publisher(for: UIApplication.didEnterBackgroundNotification)) { _ in
    data.isAppActive = false
}

.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in
    data.isAppActive = true
}

Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true) { (_) in
    guard data.isAppActive else { return }
    ...
}

So I will post an answer to this issue, as it may help someone in the future who has a similar issue. As it turns out, the problem was indeed with the animations. In most parts of my code I used the following instance method:

func animation(_ animation: Animation?) -> some View

Which btw. apparently will be deprecated in iOS 15. Source: Apple documentation The problem was that every time the view was reloaded all the views got animated regardless if they should or not. My personal guess is that this was causing some concurrency issues in the background. Anyways, the solution seams to be this

func animation<V>(_ animation: Animation?, value: V) -> some View where V : Equatable

Where value is:

A value to monitor for changes.

Using this, if you configure the view properly, even when running in the background, views will get animated when the monitored value has changed. I hope this will help someone. This definitely solved my problem!