Infrequent crash when instantiating a prefab inside an Addressables.LoadAsset response handler.

Issue #646 resolved
Ryan Murphy created an issue

Unity: 2019.3.5.f1

Odin: 2.1.9.0

EditorOnlyMode is not enabled.

Android and iOS Crash multiple devices and OS combos.

Example crash from Device samsung/SM-N960U/crownqltesq OS Version Android OS 10 / API-29 (QP1A.190711.020/N960USQU3DTAA)

What Happened?

About 1-50 instances where I call Addressables.LoadAsset for a prefab, then inside the success handler Instantiate the prefab. I recieve a crash on iOS and Android.

With 10 beta testers I recieve 1-3 crashes like this per day. I have additional logs capturing which prefabs and it is different enemy prefabs, it is not a consistent prefab. The same prefab will load successfully at other times for the same user. The Instantiate call is called on the Main Thread the best I can tell. (I spawn a coroutine and instantiate in there). I have also tried having the Instantiate inside the addressable handler and used Addressables.Instantiate instead of LoadAsset then Instantiate all with the same results. This has been accross several Unity versions.

Note: I call Addressables.LoadAsset multiple times for the same asset. I do not know if this happens on the 1st one or the Nth one. A map loads a number of server driven enemies, with many repeat enemies. A typical load has about 10 enemies simultaniously.

I use OdinInspector plugin and some MonoBehaviours are there extended versions of MonoBehaviour.

foreach path

‌ Addressabels.LoadAsset path

‌ if success

‌ Instantiate handler.result <- this is where the crash takes place. I know this because I capture some data before and after. I have the data before in FirebaseCrashalytics reports and after. I have confirmed the same crashes exist in my Crashalytics as in UnityCloudDiagnostics.

Here is one sample crash log from android. These crash logs are in my Unity Cloud Diagnostics page for project 1c449009-f9c3-43ea-b5a3-b39e110ec32c.

Native StackTrace:

Thread 0 (crashed)
0   libil2cpp.so                       0x00000000b545aaa8 il2cpp::vm::String::NewSize(int) (Object.cpp:67)
1   libil2cpp.so                       0x00000000b5e625c4 String_CreateString_m0E7BBCE09E386877E2B63BF7FA36B956BF221C93 (mscorlib17.cpp:33610)
2   libil2cpp.so                       0x00000000b5da6794 BinaryDataReader_ReadStringValue_m3C6536D58E11630D878F6C6705650ADCFD36D79A_inline (Sirenix.Serialization.cpp:38530)
3   libil2cpp.so                       0x00000000b5d8563c BinaryDataReader_PeekEntry_mE6FF9653C9ED704FAFBB1ACB46A589E0CAD06FD2 (Sirenix.Serialization.cpp:15931)
4   libil2cpp.so                       0x00000000b65f23b8 DictionaryFormatter_2_DeserializeImplementation_mABABA339B4FA552069A93AE8C2B94D98B90662C8_gshared (Generics4.cpp:94)
5   libil2cpp.so                       0x00000000b65d94d0 BaseFormatter_1_Deserialize_mB67F46DD2A020D87FB4DD87629C4C730C77F346E_gshared (Generics2.cpp:94)
6   libil2cpp.so                       0x00000000b6834f58 ComplexTypeSerializer_1_ReadValue_m428FE3024C1048547E2800B4EFBF4B0FD675EA43_gshared (Generics3.cpp:106)
7   libil2cpp.so                       0x00000000b5ba7828 UnitySerializationUtility_DeserializeUnityObject_m546A9755D37D02B206931E773A9615F51E2E7A59 (Sirenix.Serialization2.cpp:61)
8   libil2cpp.so                       0x00000000b5ba6314 UnitySerializationUtility_DeserializeUnityObject_m8E2294CCFE45E5C93332FFE18E9EA96E1405457D (Sirenix.Serialization2.cpp:26981)
9   libil2cpp.so                       0x00000000b5ba5040 UnitySerializationUtility_DeserializeUnityObject_mC5CCFC5762FD26E79E388CAC9A72323EF035B484 (Sirenix.Serialization2.cpp:0)
10  libil2cpp.so                       0x00000000b5ba44f8 UnitySerializationUtility_DeserializeUnityObject_mFBEF9C48AF8DB311F05DC240F189028938AC2334 (Sirenix.Serialization2.cpp:25816)
11  libil2cpp.so                       0x00000000b5d812b4 SerializedMonoBehaviour_UnityEngine_ISerializationCallbackReceiver_OnAfterDeserialize_mF55DE8B7411699B9E2D494F13BB35C5847D56B9E (Sirenix.Serialization.cpp:13341)
12  libil2cpp.so                       0x00000000b555dafc RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017(void (*)(), MethodInfo const*, void*, void**) (Il2CppInvokerTable.cpp:52989)
13  libil2cpp.so                       0x00000000b54543c4 il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) (Runtime.cpp:506)
14  libunity.so                        0x00000000b9a93871 scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) 
15  libunity.so                        0x00000000b9a9cdeb ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) 
16  libunity.so                        0x00000000b9aa9711 void InvokeMethod<StreamedBinaryRead>(SerializationCommandArguments const&, RuntimeSerializationCommandInfo&) 
17  libunity.so                        0x00000000b9aabd25 void ExecuteSerializationCommands<StreamedBinaryRead>(SerializationCommandProvider&, StreamedBinaryRead&, GeneralMonoObject const&) 
18  libunity.so                        0x00000000b9aa7723 void TransferScriptingObject<StreamedBinaryRead, false>(StreamedBinaryRead&, ScriptingObjectPtr, ScriptingClassPtr, SerializationCache::Data*&, ManagedReferencesRegistry*) 
19  libunity.so                        0x00000000b9aa761b void TransferScriptingObject<StreamedBinaryRead>(StreamedBinaryRead&, ScriptingObjectPtr, ScriptingClassPtr, MonoScriptCache const*) 
20  libunity.so                        0x00000000b9ac3cc9 SerializableManagedRefTransfer::Transfer(Object*, SerializableManagedRef&, StreamedBinaryRead&, bool) 
21  libunity.so                        0x00000000b9acbceb SerializedFile::ReadObject(long long, ObjectCreationMode, bool, TypeTree const**, bool*, Object&) 
22  libunity.so                        0x00000000b9ac55d3 PersistentManager::ReadAndActivateObjectThreaded(int, SerializedObjectIdentifier const&, SerializedFile*, bool, bool, PersistentManager::LockFlags) 
23  libunity.so                        0x00000000b9ac56df PersistentManager::LoadObjectsThreaded(int const*, int, LoadProgress&, bool, PersistentManager::LockFlags) 
24  libunity.so                        0x00000000b9a33041 LoadOperation::Perform() 
25  libunity.so                        0x00000000b991c591 AssetBundleLoadAssetOperation::Perform() 
26  libunity.so                        0x00000000b9a348e9 PreloadManager::ProcessSingleOperation() 
27  libunity.so                        0x00000000b9a347c5 PreloadManager::Run() 
28  libunity.so                        0x00000000b9a3475b PreloadManager::Run(void*) 
29  libunity.so                        0x00000000b9a78c5f Thread::RunThreadWrapper(void*) 
30  libc.so                            0x00000000eacc5cbb <system symbols missing> 
31  libc.so                            0x00000000eac7cdc3 <system symbols missing> 

Comments (1)

  1. Tor Esa Vestergaard

    This should be resolved in the next patch of Odin, which contains several thread safety fixes for Unity object deserialization with Odin.

  2. Log in to comment