Crash instantiating object ONLY when run without XCode


I have a tricky crash that is occurring only when we run our fully immersive app directly from the device launcher (i.e it doesn’t happen when launching from Xcode).

I haven’t been able to see any Unity prints (because they don’t show up in the Console when run outside XCode), but did manage to pull a crash log with the following stack:

As you can see, it’s instantiating an object, which has a Visual Scripting ScriptMachine, and something is going wrong downstream of the call to OnEnable (its trying to listen for an event?).

I’ll also note that this only happens when loading into a particular scene from another scene. If we launch the app in the same way directly into this scene that’s crashing, the crash doesn’t happen. So the stack above is probably happening in the first Update() after the scene was activated (loaded with SceneManager.LoadScene).

Has anyone encountered something similar? Anyone have tips on how I can do some print debugging when running a build outside of Xcode (seems like maybe I need to make a custom plugin to route Debug.Log to NSLog?).

Any help is MUCH appreciated!

Yikes! This is a tricky one. You should be able to attach to the running build from Xcode, but only if it runs long enough to attach the debugger and then trigger the error. Is this a development/debug build that you’re just launching from the home screen, or a release build? You might also get some more information out of the managed debugger if you can replicate the issue in a development build with script debugging enabled.

Are you able to trigger this behavior in the editor or a standalone build?

This is a standalone build launched from the home screen - thankfully it happens in development builds as well as release. It doesn’t repro in the editor or if launched from XCode.

I’ll see if I can get XCode to attach to the running build - I do trigger the crash interactively, so I have time to attach (but had figured it wouldn’t repro when attaching since it doesn’t happen when launching directly from debugger in XCode).

Another angle is to get console log working in a standalone, so I can narrow down which asset is spawning when it crashes. I see an idea to make a custom native plugin to route Unity logs to NSLog here:

That seem like the easiest approach?

Yeah, that should work. For iOS apps, you should be able to attach the Console app to the device and read logs, but I haven’t gotten that to work on AVP. I say use whatever tools you have at your disposal! :smiley:

I’m running into a somewhat similar issue that only reproes without the debugger attached. I wonder if they’re related somehow? Posted here: App Crashes when Opening Control Center

I’ll try to dig into the crash. @puddle_mike did you figure out a good way to debug this?

I plan to look at this again tomorrow by following the instructions at the link I posted - a custom plugin that routes Debug.Log to NSLog, so Ican observe unity logs from the Console app on my Mac.
I will say I got my first clue by having it crash using a TestFlight build I had pushed, and then reporting the crash. Then the crash + stack showed up in XCode’s bug reporting panel (I forget the exact name)…