Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Analytics crashes the game at shutdown

Discussion in 'Unity Analytics' started by grrava, Nov 18, 2023.

  1. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    46
    See the attached player log. In there you see that the analytics events at startup get send successfully. When I close the game (without doing anything else) the game actually crashes.
    It is in the creation of a webrequest by the analytics system.

    Unity 2023.2.0f1 - Analytics 5.0.1

    What can I do to fix this?
     

    Attached Files:

  2. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    398
    I have the same issue, but with Unity 2023.2.0,b14 the problem does not occur.
     
    SebT_Unity likes this.
  3. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    283
    Hi @grrava

    Could you provide a little more information on what you are testing on?
    It looks like you are testing on a touch enabled windows machine?

    It seems to be crashing maybe on attempt to flush the events when you close the game.
    I will try to reproduce using the versions you mentioned and post back here.
     
  4. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    46
    It indeed crashes when flushing the events I think. I avoided the issue by disabling analytics at shutdown, but because of that I'll never get a gameEnded event. But at least it does not crash.

    The device I'm testing on is a very classic desktop with windows 10, no touch enabled. I am using a bluetooth mouse.
     
  5. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    283
    Hi @grrava thanks, I was indeed able to reproduce the problem. I will report the problem to the team. Not sure if trying another version of the editor is an option at this point?
     
  6. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    46
    Thx @SebT_Unity, unfortunately it is indeed not an option to use another version for me, since that version fixed another issue I really need fixed.
     
  7. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    192
    Hi. I confirm we are observing this crash too, with Unity 2022.3.14f1 LTS, for Windows builds. Haven't tried yet to see if it happens on other platforms. It did not seem to occur on 2021.3.22f1 LTS.
    Cheers,
    Charles
     
  8. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    192
    Here's the stacktrace:

    Code (CSharp):
    1. 0x00007FFCDC51C433 (UnityPlayer) DebugStringToFilePostprocessedStacktrace
    2. 0x00007FFCDC51BC30 (UnityPlayer) DebugStringToFile
    3. 0x00007FFCDBD7DABD (UnityPlayer) UnityWebRequest::UnityWebRequest
    4. 0x00007FFCDBD7EB15 (UnityPlayer) UnityWebRequest::Create
    5. 0x00007FFCDAB85E9A (UnityPlayer) UnityWebRequest_CUSTOM_Create
    6. 0x000001DCAC357326 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Networking.UnityWebRequest:Create ()
    7. 0x000001DCAC35709B (Mono JIT Code) [C:\build\output\unity\unity\Modules\UnityWebRequest\Public\UnityWebRequest.bindings.cs:196] UnityEngine.Networking.UnityWebRequest:.ctor (string,string)
    8. 0x000001DCAC7717D3 (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\Runtime\WebRequestHelper.cs:22] Unity.Services.Analytics.Internal.AnalyticsWebRequest:.ctor (string,string)
    9. 0x000001DCAC7714BB (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\Runtime\WebRequestHelper.cs:43] Unity.Services.Analytics.Internal.WebRequestHelper:CreateWebRequest (string,string,byte[])
    10. 0x000001DCAC770284 (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\Runtime\Dispatcher.cs:72] Unity.Services.Analytics.Internal.Dispatcher:FlushBufferToService ()
    11. 0x000001DCAC76FB8B (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\Runtime\Dispatcher.cs:54] Unity.Services.Analytics.Internal.Dispatcher:Flush ()
    12. 0x000001DCAC73FA73 (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\AnalyticsServiceInstance.cs:323] Unity.Services.Analytics.AnalyticsServiceInstance:Flush ()
    13. 0x000001DCC38EE2AB (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\AnalyticsServiceInstance.cs:372] Unity.Services.Analytics.AnalyticsServiceInstance:ApplicationQuit ()
    14. 0x000001DCC38EE06B (Mono JIT Code) [.\Library\PackageCache\com.unity.services.analytics@5.0.1\Runtime\Runtime\AnalyticsContainer.cs:113] Unity.Services.Analytics.AnalyticsContainer:OnDestroy ()
    15. 0x000001DCAB9C72A8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    16. 0x00007FFCF9E44B6E (mono-2.0-bdwgc) mono_jit_set_domain
    17. 0x00007FFCF9D7D1F4 (mono-2.0-bdwgc) mono_object_get_virtual_method
    18. 0x00007FFCF9D7D36C (mono-2.0-bdwgc) mono_runtime_invoke
    19. 0x00007FFCDB88C06D (UnityPlayer) scripting_method_invoke
    20. 0x00007FFCDB87146C (UnityPlayer) ScriptingInvocation::Invoke
    21. 0x00007FFCDB871706 (UnityPlayer) ScriptingInvocation::InvokeChecked
    22. 0x00007FFCDB8CA6D5 (UnityPlayer) SerializableManagedRef::CallMethod
    23. 0x00007FFCDB86C67C (UnityPlayer) MonoBehaviour::WillDestroyComponent
    24. 0x00007FFCDADD990D (UnityPlayer) GameObject::WillDestroyGameObject
    25. 0x00007FFCDB3443DA (UnityPlayer) PreDestroyRecursive
    26. 0x00007FFCDB342AE0 (UnityPlayer) DestroyObjectHighLevel_Internal
    27. 0x00007FFCDB3428D6 (UnityPlayer) DestroyObjectHighLevel
    28. 0x00007FFCDB34DC5A (UnityPlayer) CleanupAllObjects
    29. 0x00007FFCDB34E58D (UnityPlayer) CleanupEngine
    30. 0x00007FFCDB372172 (UnityPlayer) PlayerCleanup
    31. 0x00007FFCDB90E061 (UnityPlayer) PerformMainLoop
    32. 0x00007FFCDB90CFBB (UnityPlayer) MainMessageLoop
    33. 0x00007FFCDB9136CD (UnityPlayer) UnityMainImpl
    34. 0x00007FFCDB9156CB (UnityPlayer) UnityMain
    35. 0x00007FF6BFCD11F2 (GAME_NAME) __scrt_common_main_seh
    36. 0x00007FFE5B03257D (KERNEL32) BaseThreadInitThunk
    37. 0x00007FFE5C7AAA58 (ntdll) RtlUserThreadStart
    Can you please help on finding at least a workaround? We're on latest Analytics version and every single exit of the game from all players and QA team provokes this crash, flooding JIRA with thousands of undesired, unfixable (it seems) entries.

    Ideally, I'd want to disable completely Analytics right before the game exits, to avoid sending web requests upon exit, as it seems like it's the cause of the issue?

    Note that this stacktrace is from a debug Mono build (for faster build times), but it happens in the same way with similar stacktrace in IL2CPP (used for release builds).

    Thank you.
     
  9. Haze-Games

    Haze-Games

    Joined:
    Mar 1, 2015
    Posts:
    192
    Alright, some progress here. I think I have found a solution. We had not yet upgraded the code to use the new consent flow, we were still using:

    Code (CSharp):
    1. UGSconsentIdentifiers = await Unity.Services.Analytics.AnalyticsService.Instance.CheckForRequiredConsents();
    We migrated to the new consent flow for latest Analytics version, which allows us now to call this function when clicking the Exit button of the game:

    Code (CSharp):
    1. AnalyticsService.Instance.StopDataCollection();
    This at least solves many crashes upon "proper game exit".

    Note: The migration mentioned in the link above is mandatory, otherwise it'll use the old flow and StopDataCollection() will do nothing!

    However, it still crashed if ALT+F4 was pressed, because not using the Exit button. By adding StopDataCollection() to OnApplicationQuit(), it also solves the crash upon hard exit.

    So, it's definitely related to Analytics still trying to perform stuff OnApplicationQuit(). This might be something Unity will want to solve to avoid everyone having to perform these changes. I didn't see the documentation mentioning calling StopDataCollection() was mandatory before exiting the game, so I don't think this is intended?

    Thank you!

    @grrava and @manuelgoellnitz You may want to try this out in case it fixes it for you for now ;)
     
    MiTschMR likes this.
  10. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    522
    I can confirm the crashes as well on iOS. Need to test a new build tomorrow with the fix you posted.
     
    Haze-Games likes this.
  11. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    522
    Indeed, the crashes stopped after putting StopDataCollection() to OnApplicationQuit(). I put a FlushEvents() before stopping the data collection to still get events that have not been sent previously.
     
  12. SebT_Unity

    SebT_Unity

    Unity Technologies

    Joined:
    Jun 21, 2021
    Posts:
    283
    Hey folks, 5.0.2 has been released targeting this bug. Can you try updating and letting us know if this resolves the issue? Initial testing looked good in our tests but would like to have your feedback.
     
    manuelgoellnitz likes this.
  13. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    522
    Hey Seb, do I interpret the release notes right that this is only targeting 2023.x?
    Analytics no longer throws a fatal exception on shutdown for builds made with 2023 editor versions


    I ask because I got the crashes with builds made on 2022.3.14f1.
     
  14. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    522
    From my side I can confirm that Analytics version 5.0.2 fixes the crashes on shutdown. Nice work!
     
    SebT_Unity and sajkowart like this.
  15. manuelgoellnitz

    manuelgoellnitz

    Joined:
    Feb 15, 2017
    Posts:
    398
    For me, 5.0.2. also seems to work. :)
     
  16. grrava

    grrava

    Joined:
    Nov 11, 2012
    Posts:
    46
    Indeed, the issue seems to be fixed in 5.0.2. Thanks!
     
    SebT_Unity likes this.
  17. tessellation

    tessellation

    Joined:
    Aug 11, 2015
    Posts:
    396
    I was able to reproduce this with Unity 2021.3.34 LTS and Analytics 4.4.2 on iOS.

    @SebT_Unity Could we get this fix back-ported to version 4 for those of us that don't want to update to the new consent flow yet?
     
  18. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    539
    Pretty sure we are having this bug on 2022.3.17
    Code (CSharp):
    1. Thread 0 name:
    2. Thread 0 Crashed:
    3. 0   libsystem_kernel.dylib            0x00000001e7d49fbc __pthread_kill + 8 (:-1)
    4. 1   libsystem_pthread.dylib           0x000000020a6cf680 pthread_kill + 268 (pthread.c:1681)
    5. 2   libsystem_c.dylib                 0x00000001a8644dd0 raise + 32 (raise.c:30)
    6. 3   UnityFramework                    0x0000000107209144 DebugStringToFilePostprocessedStacktrace(DebugStringToFileData const&) + 1228 (LogAssert.cpp:1134)
    7. 4   UnityFramework                    0x000000010720960c DebugStringToFile(DebugStringToFileData const&) + 600 (LogAssert.cpp:1198)
    8. 5   UnityFramework                    0x0000000106e6b5bc DebugStringToFile<core::basic_string<char> > + 84 (LogAssert.h:148)
    9. 6   UnityFramework                    0x0000000106e6b5bc UnityWebRequestManager::Register(UnityWebRequest*) + 236 (UnityWebRequestManager.cpp:83)
    10. 7   UnityFramework                    0x0000000106e6b4a0 UnityWebRequest::UnityWebRequest(MemLabelId) + 52 (UnityWebRequest.cpp:250)
    11. 8   UnityFramework                    0x000000010ac72b64 UnityWebRequest_Create_m0180FA724ACCE19C0C761A8B7AF280A489639CE9 + 36 (UnityEngine.UnityWebRequestModule.cpp:5581)
    12. 9   UnityFramework                    0x000000010ac72b64 UnityWebRequest__ctor_mD4739B0BF1C4937479A83B24B531C6B819712A3E + 80 (UnityEngine.UnityWebRequestModule.cpp:5647)
    13. 10  UnityFramework                    0x000000010a8a0980 AnalyticsWebRequest__ctor_m8CA36BAF33C32134D350FC88E7BF795AFFDFD77D + 16 (Unity.Services.Analytics.cpp:13791)
    14. 11  UnityFramework                    0x000000010a8a0980 WebRequestHelper_CreateWebRequest_m06C697E4C704BADC84F815F3F84A4144708DDFFA + 152 (Unity.Services.Analytics.cpp:13851)
    15. 12  UnityFramework                    0x000000010a8a033c InterfaceFuncInvoker3<Il2CppObject*, String_t*, String_t*, ByteU5BU5D_tA6237BF417AE52AD70CFB4EF24A7A82613DF9031*>::Invoke(unsigned short, Il2CppClass*, Il2CppObject*, String_t*, String_t*, ByteU5BU... + 40 (Unity.Services.Analytics.cpp:218)
    16. 13  UnityFramework                    0x000000010a8a033c Dispatcher_FlushBufferToService_m55AC50B02B30BD4ED1E554D794AA5DEE9FB77C39 + 628 (Unity.Services.Analytics.cpp:13528)
    17. 14  UnityFramework                    0x000000010a894fac InterfaceActionInvoker0::Invoke(unsigned short, Il2CppClass*, Il2CppObject*) + 32 (Unity.Services.Analytics.cpp:97)
    18. 15  UnityFramework                    0x000000010a894fac AnalyticsServiceInstance_Flush_mB8F0ED919FB47026C5CB61DD3562FAA09009C21E + 932 (Unity.Services.Analytics.cpp:4602)
    19. 16  UnityFramework                    0x000000010a898e54 AnalyticsContainer_OnDestroy_m27C97541D5D0E67B2F4FA9D110EFDD12C88866DD + 68 (Unity.Services.Analytics.cpp:7478)
    20. 17  UnityFramework                    0x0000000107ea8764 il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**) + 100 (Runtime.cpp:606)
    21. 18  UnityFramework                    0x0000000107ea86ac il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**) + 84 (Runtime.cpp:592)
    22. 19  UnityFramework                    0x0000000106cca6ac scripting_method_invoke(ScriptingMethodPtr, ScriptingObjectPtr, ScriptingArguments&, ScriptingExceptionPtr*, bool) + 124 (ScriptingApi_Il2Cpp.cpp:290)
    23. 20  UnityFramework                    0x0000000106cd7a7c ScriptingInvocation::Invoke(ScriptingExceptionPtr*, bool) + 120 (ScriptingInvocation.cpp:298)
    24. 21  UnityFramework                    0x0000000106cda258 Invoke + 12 (ScriptingInvocation.h:72)
    25. 22  UnityFramework                    0x0000000106cda258 ScriptingInvocation::InvokeChecked(ScriptingExceptionPtr*) + 60 (ScriptingInvocation.cpp:123)
    26. 23  UnityFramework                    0x0000000106d28774 SerializableManagedRef::CallMethod(Object&, ScriptingMethodPtr) + 96 (SerializableManagedRef.cpp:623)
    27. 24  UnityFramework                    0x0000000106ce6310 CallMethodInactive + 12 (MonoBehaviour.h:81)
    28. 25  UnityFramework                    0x0000000106ce6310 MonoBehaviour::WillDestroyComponent() + 340 (MonoBehaviour.cpp:333)
    29. 26  UnityFramework                    0x0000000106b082d0 GameObject::WillDestroyGameObject() + 56 (GameObject.cpp:114)
    30. 27  UnityFramework                    0x0000000106bd4800 PreDestroyRecursive(GameObject&, unsigned long*) + 160 (GameObjectUtility.cpp:1774)
    31. 28  UnityFramework                    0x0000000106bd5090 DestroyGameObjectHierarchy + 28 (GameObjectUtility.cpp:1841)
    32. 29  UnityFramework                    0x0000000106bd5090 DestroyObjectHighLevel_Internal(Object*, bool) + 392 (GameObjectUtility.cpp:2032)
    33. 30  UnityFramework                    0x0000000106bcdf58 CleanupAllObjects() + 284 (SaveAndLoadHelper.cpp:444)
    34. 31  UnityFramework                    0x0000000106bce62c CleanupEngine() + 44 (SaveAndLoadHelper.cpp:584)
    35. 32  UnityFramework                    0x0000000106bddd70 PlayerCleanup(bool) + 72 (Player.cpp:698)
    36. 33  UnityFramework                    0x0000000107299bc4 UnityCleanup + 16 (LibEntryPoint.mm:221)
    37. 34  UnityFramework                    0x0000000105023e28 -[UnityAppController applicationWillTerminate:] + 36 (UnityAppController.mm:531)
    Seems to be the same you are talking about, anybody else?