Analyzing root cause for crash on device (Unity 4)

Hello everybody,

I would like some opinions in regards to my assumption:
After upgrading to Unity 4, the project crashes on the device and working smoothly in the editor.
My assumption is that it is Unity’s fault, and not my project.

This is what I have done:

  • The starting point is that the project works perfectly in Unity 3.5 - both in editor and on the device
  • I installed Unity 4, allowed Unity to upgrade the project
  • I modified the project to eliminate all deprecation warnings (e.g. gameObject.active changed to gameObject.SetActive() etc)
  • I modified the SetActive behavior where needed, to consider the new Unity 4 approach that SetActive now works recursively (whereas gameObject.active wasn’t)
  • I reached a place where the project runs smoothly again in the Editor
  • Deployed to the iOS simulator or device.
  • Now, crashes occur at random places, and nothing is sent back to the Xcode console. Note that I do see some other Debug.Log() commands getting back to the console, so I know I am looking at the right place and the simulator is sending messages back.
  • I then tried eliminating some stuff, and reducing all objects as much as I can, but still cannot identify where is the crash.
  • From what I have experienced throughout this process, it seems that there is a problem when instantiating objects.
  • I would assume that if it is a null reference error that I can fix, it would either also occur in the editor, or at least, would show in the Xcode error log.

So, am I completely wrong to assume the problem is not on my part?

The results I got from the Xcode debugger are below.
Note - as the only thing I saw on crash was the word “lldb” - I googled it, and figured out it was the debugger type.
So I changed to the other Xcode debugger (GDB), hoping it may give more details. It did, but still not useful.

Using GDB debugger instead of LLDB:

[Switching to process 2196 thread 0x14d03]
sharedlibrary apply-load-rules all
warning: Trying to remove a section from the ordered section list that did not exist at 0xcee000.
warning: Trying to remove a section from the ordered section list that did not exist at 0xcee000.
Warning: the current language does not match this frame.
[unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown][unknown](gdb)

From Xcode Debug Navigator:

#0	0x001e585b in Object::GetInstanceID() const [inlined] at /Applications/buildAgent/work/812c4f5049264fad/./Runtime/BaseClasses/BaseObject.h:438
#1	0x001e5852 in CollectAndProduceGameObjectHierarchy(Unity::GameObject, Transform*, vector_map<long, long, std::less<long>, stl_allocator<std::pair<long, long>, (MemLabelIdentifier)97, 16> >*) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:46
#2	0x001e59ee in CollectAndProduceGameObjectHierarchy(Unity::GameObject, Transform*, vector_map<long, long, std::less<long>, stl_allocator<std::pair<long, long>, (MemLabelIdentifier)97, 16> >*) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:77
#3	0x001e5aef in CollectAndProduceClonedIsland(Object, vector_map<long, long, std::less<long>, stl_allocator<std::pair<long, long>, (MemLabelIdentifier)97, 16> >*) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:116
#4	0x001e5b5e in CloneObjectImpl at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:173
#5	0x001e5f6e in InstantiateObject(Object, Vector3f const, Quaternionf const, vector_map<long, long, std::less<long>, stl_allocator<std::pair<long, long>, (MemLabelIdentifier)97, 16> >) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:262
#6	0x001e607e in InstantiateObject(Object, Vector3f const, Quaternionf const) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/CloneObject.cpp:293
#7	0x0042ee80 in Object_CUSTOM_INTERNAL_CALL_Internal_InstantiateSingle(ScriptingObjectOfType<Object>, Vector3f const, Quaternionf const) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/iPhoneSimulatorPlayerUnityLib/UnityEngineObject.cpp:34
#8	0x0f9d645e in 0x0f9d645e ()
#9	0x0f9d6419 in 0x0f9d6419 ()
#10	0x0f9d63ae in 0x0f9d63ae ()
#11	0x0fddd7e7 in 0x0fddd7e7 ()
#12	0x0a7c1609 in 0x0a7c1609 ()
#13	0x0070c302 in mono_jit_runtime_invoke at /Applications/buildAgent/work/6343c66c7f51e77a/mono/mini/mini.c:4889
#14	0x008fd96a in mono_runtime_invoke at /Applications/buildAgent/work/6343c66c7f51e77a/mono/metadata/object.c:2615
#15	0x002d1be2 in scripting_method_invoke(ScriptingMethod*, MonoObject*, ScriptingArguments, MonoException**) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Scripting/Backend/Mono/ScriptingBackendApi_Mono.cpp:155
#16	0x002d1695 in ScriptingInvocation::Invoke(MonoException**) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Scripting/Backend/ScriptingInvocation.cpp:140
#17	0x002d170b in ScriptingInvocation::Invoke() at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Scripting/Backend/ScriptingInvocation.cpp:129
#18	0x002c5bee in MonoBehaviour::CallMethodIfAvailable(int) [inlined] at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Mono/MonoBehaviour.cpp:529
#19	0x002c5b96 in MonoBehaviour::CallUpdateMethod(int) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Mono/MonoBehaviour.cpp:602
#20	0x002c5c59 in MonoBehaviour::Update() at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Mono/MonoBehaviour.cpp:607
#21	0x001e45d6 in BehaviourManager::UpdateBehaviour(Behaviour) [inlined] at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/Behaviour.cpp:178
#22	0x001e45ce in void BaseBehaviourManager::CommonUpdate<BehaviourManager>() at /Applications/buildAgent/work/812c4f5049264fad/Runtime/GameCode/Behaviour.cpp:157
#23	0x0029e5cc in PlayerLoop(bool, bool, IHookEvent*) at /Applications/buildAgent/work/812c4f5049264fad/Runtime/Misc/Player.cpp:1664
#24	0x0001f0cb in UnityPlayerLoop() at /Applications/buildAgent/work/812c4f5049264fad/PlatformDependent/iPhonePlayer/LibEntryPoint.mm:372
#25	0x000033bb in -[AppController Repaint] at /Users/db/Developer/unity/Teddy/Build/Classes/AppController.mm:526
#26	0x00003321 in -[AppController RepaintDisplayLink] at /Users/db/Developer/unity/Teddy/Build/Classes/AppController.mm:509
#27	0x01ec1a88 in CA::smile:isplay::smile:isplayLink::dispatch(unsigned long long, unsigned long long) ()
#28	0x01ec1bcd in CA::smile:isplay::EmulatorDisplayLink::callback(__CFRunLoopTimer*, void*) ()
#29	0x02dcd8c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#30	0x02dcee74 in __CFRunLoopDoTimer ()
#31	0x02d2b2c9 in __CFRunLoopRun ()
#32	0x02d2a840 in CFRunLoopRunSpecific ()
#33	0x02d2a761 in CFRunLoopRunInMode ()
#34	0x036e71c4 in GSEventRunModal ()
#35	0x036e7289 in GSEventRun ()
#36	0x0168ec93 in UIApplicationMain ()
#37	0x0000427a in main at /Users/db/Developer/unity/Teddy/Build/Classes/main.mm:22
#38	0x000023f5 in start ()

We’re tracking down a similar issue on our game that seems to be related to some changes they’ve made in UnloadUnusedAssets. We’re getting ready to fire off a repro project to the Unity team, but for us the problem was related to the way we were cleaning up certain assets. UnloadUnused is now asynch, so if we were loading a resource (using resources.load) that UnloadUnused was in the process of unloading, it would cause things to crash. This was only happening in the player, and never in the editor.

Hey, thanks a lot for this input. It would be great if you can post here once you hear something about it from Unity. I was unable to create a reproduction project, so after 24 hours of attempting, I reverted back to 3.5 and all is good with the world again.

ugh. just saw this thread and realized i’m seeing the exact same crash stack on android after upgrading to unity4.
sad monkey.
unfortunately, i did a bunch of work in 4 that i now can’t pull back onto 3.5 since the scene and prefab formats aren’t the same. I would say this is a huge problem. anybody from unity able to chime in?

stack from android output:
12-05 20:19:57.370: I/DEBUG(25322): #00 pc 00235900 /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z36CollectAndProduceGameObjectHierarchyRN5Unity1 0GameObjectEP9TransformP10vector_mapIllSt4lessIlE1 3stl_allocatorISt4pairIllEL18MemLabelIdentifier97E Li4EEE)
12-05 20:19:57.370: I/DEBUG(25322): #01 pc 00235d18 /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z36CollectAndProduceGameObjectHierarchyRN5Unity1 0GameObjectEP9TransformP10vector_mapIllSt4lessIlE1 3stl_allocatorISt4pairIllEL18MemLabelIdentifier97E Li4EEE)
12-05 20:19:57.370: I/DEBUG(25322): #02 pc 00236858 /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z29CollectAndProduceClonedIslandR6ObjectP10vecto r_mapIllSt4lessIlE13stl_allocatorISt4pairIllEL18Me mLabelIdentifier97ELi4EEE)
12-05 20:19:57.370: I/DEBUG(25322): #03 pc 00236e50 /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_ZL15CloneObjectImplP6ObjectR10vector_mapIllSt4le ssIlE13stl_allocatorISt4pairIllEL18MemLabelIdentif ier97ELi4EEE)
12-05 20:19:57.370: I/DEBUG(25322): #04 pc 0023779c /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z17InstantiateObjectR6ObjectRK8Vector3fRK11Quate rnionfR10vector_mapIllSt4lessIlE13stl_allocatorISt 4pairIllEL18MemLabelIdentifier97ELi4EEE)
12-05 20:19:57.375: I/DEBUG(25322): #05 pc 00237b7c /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z17InstantiateObjectR6ObjectRK8Vector3fRK11Quate rnionf)
12-05 20:19:57.375: I/DEBUG(25322): #06 pc 005167ac /data/data/com.roguerocketgames.gameygam/lib/libunity.so (_Z54Object_CUSTOM_INTERNAL_CALL_Internal_Instanti ateSingle21ScriptingObjectOfTypeI6ObjectERK8Vector 3fRK11Quaternionf)

Hi Richard, sorry to hear you are stuck with no way to roll back, but at least now that this type of crash gains “popularity” maybe someone at Unity will pull their heads out of their… ahm… you know.

I can tell you two things:

  1. After I rolled back (although it was a painful couple of days), I am back to normal, no crashes and everything is back to its normal state.

  2. As for Unity chiming in, I can tell you that I have been communicating with them a little, but we ended discussions when they insisted they cannot do anything unless I provide a test case.
    At this point I realized I either need to send them my entire source code, or to spend many hours if not days in trying to narrow down a smaller test case. So I left it there.

You shouldn’t be afraid of sending your actual product as a bug-case, if you cannot do another repro. The folks @Unity will probably not use your product for anything more than tracking the bug down, if that’s the reason why your holding back. I mean, would be kind of bad for them to even talk about it in public.

I submitted mine. hopefully something useful happens.

this is now:
(Case 504812) random crash while playing game on Android

Hey, anybody got any news about this?

I just made a bug report of my own with steps to reproduce it. It’s case 509411, and I mentioned that it may be a duplicate of 504812. (Note: I only mentioned Android, and explained some steps to make it consistently crash on some Samsung phones, which are all we have on hand.)

Cool. Can you provide links to the case pages? The case search form expects a different case number format. (or is there any other place that these case numbers can be searched for?)

Sorry, I can’t. Their bug tracker seems to use the full ticket ID in lieu of login/password, so if you see the bug report page, you can also see too much of my information.

Understood.

can a Unity rep please weigh in on this? its keeping us from being able to move the team to our (very expensive new) Unity 4 licenses. its sort of a big problem, and we have to keep and maintain 2 versions (or 3) of unity, making our lives very annoying.

I was in touch with unity support yesterday and one bug is fixed (pending next unity release) and the other is actively being worked on. I’m referring to the two android issues. I’m not sure if the iOS issue is the same or not.

Can anyone confirm if the latest Unity release has fixed this?
For me Unity 4.x is still a “no fly zone”…

The most serious crashes have been fixed, but I just found and reported an infrequent crash. Unity 3.5 also occasionally crashes without good reason, so I don’t know whether Unity 4 is actually less stable.

It’s good enough for us to have put our game back on the market.

We had very similar crashes and found out that not using Get instanceID() does the trick.

For example we had a simple method that was doing an instance id verification and would spawn a particle system afterwards (not depending on the verification). Whenever this method was called in a PC/Mac build the particle system wouldn’t be spawned and in iOS the app would just crash at that moment. It’s like the method would quit after the check but before finishing. We have replaced this with a simple reference check and it works flawlessly now.

I’ve tested builds with 3.5 and 4.0.1 and both do the same thing. So it could be GetInstanceID() in-game. It only worked in the editor for us. Anyway, I will try to find more info on this.

EDIT: I got the Get instanceID to work. Apparently what was causing the crash was that it was called on a null reference. The editor does not throw exceptions in that case, that is a bug ! Why isn’t it caught by the editor??