Using actor in iOS 14 crashes on initialization using Xcode 13.2

I'm using the release version of Xcode 13.2 (13C90) downloaded from the Developer Website (not the App Store) but also observed this behavior in Beta 2 and the release candidate.

Steps to reproduce

  1. Create a brand new Swift UI app and initialize an actor. This is the entire diff of my app from the default project:
diff --git a/TestApp/ContentView.swift b/TestApp/ContentView.swift
index 8eb8cb1..2367c25 100644
--- a/TestApp/ContentView.swift
+++ b/TestApp/ContentView.swift
@@ -8,14 +8,16 @@
 import SwiftUI
 struct ContentView: View {
+    @ObservedObject var testState: TestState
     var body: some View {
         Text("Hello, world!")

diff --git a/TestApp/TestAppApp.swift b/TestApp/TestAppApp.swift
index bccc88e..b5b575f 100644
--- a/TestApp/TestAppApp.swift
+++ b/TestApp/TestAppApp.swift
@@ -11,7 +11,7 @@ import SwiftUI
 struct TestAppApp: App {
     var body: some Scene {
         WindowGroup {
-            ContentView()
+            ContentView(testState: TestState())
diff --git a/TestApp/TestState.swift b/TestApp/TestState.swift
index 3b3fb0e..b11c044 100644
--- a/TestApp/TestState.swift
+++ b/TestApp/TestState.swift
@@ -6,3 +6,13 @@
 import Foundation
+class TestState: ObservableObject {
+    init() {
+        let testActor = TestActor()
+    }
+actor TestActor {
  1. Set the deployment target to 14.0 (I've experimented with different versions up to 14.7 with no change in behavior).

  2. Launch the app on an iOS 14 device (I've seen this issue on devices running 14.4.2 and 14.8.1).

  3. Terminate the app (either via Xcode or swiping up in the list of apps).

  4. Attach to the process via Debug > Attach to Process by PID or Name (so the error message can be observed).

  5. Relaunch the app on the phone.

Expected behavior

App launches correctly on both initial and subsequent launches.

Observed behavior

After the initial successful launch (directly from Xcode), all subsequent launches of the app crash immediately, with Xcode highlighting the line "let testActor = TestActor()" with the following error:

Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

Unfortunately I can't seem to get any additional information (happy for any tips) but here are some screenshots of what I see in Xcode:

If I comment out the line that initializes the actor, the app no longer crashes. The crash will also happen when the app is distributed via TestFlight immediately on launch. Some things I've tried (most of these don't necessarily make sense, but I was trying anything that seemed to work :slight_smile:):

  1. Adding -Wl,-weak-lswift_Concurrency -Wl,-rpath,/usr/lib/swift to linker flags. The release notes say this is specifically for an error around Concurrency library not loading, but I'm not seeing that specific error / this didn't fix anything.

  2. Disabling bitcode

  3. Manually adding the Concurrency library in the "Link Binary With Libraries" Build Phase section.

Are there any other debugging steps I can take? I'm running the latest macOS (12.1) on a brand new laptop (MacBook Pro M1 Max) and seeing this issue with a brand new project across a number of devices. I haven't seen other reports of this issue so I'm slightly baffled but happy to try anything and everything as this is a large blocker for an app we're trying to test.


PS. The async / await and actor functionality is incredible and has already addressed a number of bugs, but many of our users are on iOS 14.

1 Like

Hey! Did you fix this crash?

I'm seeing the exact same thing. Interested to know if there is a fix for this

In my observation it crashes if you use new concurrency APIs on lower versions like iOS 14/13 using Xcode 13.2.1. It is just not Actor. I raised similar issue couple days back and I am also looking for solutions.

Hi! Looking at the other thread it looks like the issue I experienced over a month-and-a-half ago is finally reproducible :-)

I actually submitted a technical support incident and have been working with a contact at Apple to diagnose my specific issue. What became challenging is that the behavior of the sample app vs. my production app changed. Before the test app would work on initial launch from either Xcode or when distributed to TestFlight and then crash on subsequent launches. Then it started crashing on initial launch in Xcode.

Then my sample app just worked when distributed via TestFlight, both initial and subsequent launch which was strange (since Xcode hadn't changed) but promising to me (possibly the bitcode was rebuilt differently on Apple's side). So I attempted to re-distribute my production app via TestFlight... and it crashed on initial launch again.

The crash report was slightly different and we were able to diagnose that it was because I was using iOS 15 compatibility checks and there's a bug where sometimes they're not stripped out causing immediate crashes. We were able to apply a workaround and now it appears my app works when distributed via TestFlight but I observe the issue where subsequent launches when run from within Xcode crash on launch. The 0x0000000000000000 EXC_BAD_ACCESS observed in the linked thread appears to be the same issue so hopefully it's addressed soon.

If none of the shared workarounds work, my contact's suggestion is to file a bug report, and then file a technical support incident with a link to the report so that they can work with you one-on-one with code. My contact was very helpful. If you take this approach you should mention my bug report — FB9779815