Unity iOS build crashing on scene load

Hey guys,

I’ve been pulling my hair out over this issue for about 2 months now. My game is crashing only on an iOS build when attempting to load in a new scene. When running in the editor, all scenes work just fine, no warnings or errors.

When going from the main menu to my first level, the game crashes when I try to load a scene that has my gameplay logic (empty scene load just fine). What’s odd is if I set my first level as the initial starting scene rather than the main menu, it works just fine (until it tries to load level 2).

In the Xcode debugger I can see some Debug.Log() statements from some of my game logic being called as the new scene starts, so I know the scene is being loaded somewhat successfully but it crashes/freezes before the new scene appears. I don’t think it’s a memory issue, as the game only uses 1Gb of ram, but I could be wrong.

My question is, how can I narrow it down to what game logic code is causing the issue?

Xcode is reporting the game is crashing after calling this function:
UnityFramework`il2cpp::vm::LivenessState::AddProcessObject:

with this being the cause:
AssetGarbageCollectorHelper (7): EXC_BAD_ACCESS (code=1, address=0x135)

Some things I’ve tried:

  • Backtrace.io (doesn’t yield any significant insight)
  • Deleting the library folder
  • Using scene index number rather than scene string name
  • Upgrading Unity (was using 2022.3.16f1)
  • Disabling “Strip Engine Code”
  • Disabling “Use Incremental GC”
  • Manually setting “Always embed swift standard libraries” to “Yes” in Xcode
  • Manually adding “GameKit” to linked libraries in Xcode

I’m using Unity 2023.2.10f1
Xcode 15.2
testing device: iPad Pro 10.5 (2017) iPadOS 17.3.1
testing device 2: iPhone 7+ (2016) iOS 15.3

Any guidance on this would be greatly appreciated.

1 Like

1 Answer

1

Hey guys,

After days of meticulously going through the code I found the answer. It was because I was using GameObject.Find() and I guess it was causing some kind of race condition.

Lesson learned, don’t use GameObject.Find() in Awake or Start if possible.

You learned the wrong lesson - GameObject.Find() is completely fine. EXC_BAD_ACCESS is an iOS engine bug. Your code was triggering the bug but was not causing it.

Yes, very frustrating. Thanks for the information!