Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Game crashes randomly at GarbageCollectSharedAssets

Discussion in 'iOS and tvOS' started by mbast, Sep 7, 2023.

  1. mbast

    mbast

    Joined:
    Dec 19, 2018
    Posts:
    15
    Hello guys!

    I'm having a weird issue when running my game on iOS:
    Some minutes after running the game freezes and throws a crash. Usually, this happens when loading a scene, but sometimes it crashes during gameplay.

    This is the stack trace I get in Crashlytics, it looks like the trace people are getting in this old thread:
    Code (csharp):
    1.  
    2. Crashed: com.apple.main-thread
    3. 0  UnityFramework                 0x1724360 il2cpp::vm::LivenessState::AddProcessObject(Il2CppObject*, il2cpp::vm::LivenessState*) + 44
    4. 1  UnityFramework                 0x17240b8 il2cpp::vm::LivenessState::TraverseGCDescriptor(Il2CppObject*, il2cpp::vm::LivenessState*) + 60
    5. 2  UnityFramework                 0x1723f28 il2cpp::vm::LivenessState::TraverseObjects() + 116
    6. 3  UnityFramework                 0x172469c il2cpp::vm::Liveness::FromStatics(void*) + 348
    7. 4  UnityFramework                 0x6dc840 GarbageCollectSharedAssets(bool, bool) + 1644
    8. 5  UnityFramework                 0x7056e0 UnloadUnusedAssetsOperation::IntegrateMainThread() + 28
    9. 6  UnityFramework                 0x70478c PreloadManager::UpdatePreloadingSingleStep(PreloadManager::UpdatePreloadingFlags, int) + 228
    10. 7  UnityFramework                 0x705248 PreloadManager::UpdatePreloading() + 276
    11. 8  UnityFramework                 0x6e6f20 ExecutePlayerLoop(NativePlayerLoopSystem*) + 100
    12. 9  UnityFramework                 0x6e6f60 ExecutePlayerLoop(NativePlayerLoopSystem*) + 164
    13. 10 UnityFramework                 0x6e7218 PlayerLoop() + 280
    14. 11 UnityFramework                 0xdc848c UnityPlayerLoopImpl(bool) + 112
    15. 12 UnityFramework                 0x17680 UnityRepaint + 40
    16. 13 QuartzCore                     0x29328 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 820
    17. 14 QuartzCore                     0x146e68 CA::Display::DisplayLink::dispatch_deferred_display_links(unsigned int) + 380
    18. 15 UIKitCore                      0x64dd94 _UIUpdateSequenceRun + 84
    19. 16 UIKitCore                      0xcb2894 schedulerStepScheduledMainSection + 144
    20. 17 UIKitCore                      0xcb1df0 runloopSourceCallback + 92
    21. 18 CoreFoundation                 0xd3128 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    22. 19 CoreFoundation                 0xdf7b4 __CFRunLoopDoSource0 + 176
    23. 20 CoreFoundation                 0x645e8 __CFRunLoopDoSources0 + 244
    24. 21 CoreFoundation                 0x7a0d4 __CFRunLoopRun + 828
    25. 22 CoreFoundation                 0x7f3ec CFRunLoopRunSpecific + 612
    26. 23 GraphicsServices               0x135c GSEventRunModal + 164
    27. 24 UIKitCore                      0x39cf58 -[UIApplication _run] + 888
    28. 25 UIKitCore                      0x39cbbc UIApplicationMain + 340
    29. 26 UnityFramework                 0x172b4 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 92
    30. 27 Hero's Quest                   0x57d4 main + 28 (main.mm:28)
    31. 28 ???                            0x1c02f4dec (Missing)
    32.  
    It looks like the game is crashing when the garbage collector is working, that would explain why it crashes when loading scenes.

    The game uses Addressables for all assets and scenes, I'm on Unity 2022.3.8f1, IL2CPP.
    What I've tried so far without any success:
    - Disabling incremental GC
    - Temporarily removing any JSON serialization/deserialization
    - Commenting out all addressable "Release" calls
    - Building with minimal scenes (5 instead of all 60+)

    I've tried everything I could and nothing changes anything, the game runs fine, loads scenes, and does everything as expected but out of nowhere it freezes, doesn't crash to the home screen but logs the crash to Firebase. When the game freezes I can hear the audio chipping out.

    Is there anything else I could try? Is this a known ting with 2022.3.x?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,755
    This is usually an indication of some memory corruption in a managed object allocated from the heap. The code in il2cpp::vm::LivenessState traverses the managed heap, building a graph of object references and trying to find assets that are no longer used and can be collected. It is not usually the cause of these problems, but it does often discover them.

    Usually the causes fall into one of two camps:
    1. Some code in your project is using unsafe C# code or native code that touches managed objects somehow, and causes this corruption.
    2. Some code in Unity is corrupting a managed object
    If you inspect your code and don't find anything in camp (1), can you file a bug report with a project that causes this? WE can investigate it, and hopefully track down the code in Unity causing this, if that is the problem.

    If you want to report a bug, instructions about how to do that are here: https://unity.com/releases/editor/qa/bug-reporting
     
  3. mbast

    mbast

    Joined:
    Dec 19, 2018
    Posts:
    15
    The issue started happening after upgrading from 2021 lts to 2022 lts and the introduction of the addressable a package. There are no “unsafe” keyword in the entire project, nor am I messing with managed code. I tried to reproduce with an empty project without any success, it might be a mix of too many addressables groups or the mix of packages the game uses. Sadly I don’t feel comfortable with sending my project.

    When running from Xcode and looking at the logs every crash is happening seconds after an asset is loaded/unloaded inside an async function. I do lots of load/release calls since all spritesheets are in “pack separate” asset groups and loaded on demand.
    Android is crashing in the same way, I just can’t confirm if the stack trace is the same since I’m not uploading debug symbols to firebase on development builds, but by the logcat I can see it’s happening at the same location as iOS.

    Said that, I noticed the crashes stopped happening once I set stripping level to minimal (from high), low still crashes. Never had any issues with high stripping level before 2022+addressables. I’ll have to accept a higher bundle size until this can be fixed.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,755
    Interesting - I would not expect the stripping level to impact behavior like this. Can you submit this project with a bug report? It does sound like a problem on the Unity side. We definitely want to investigate and correct it.