Search Unity

Bug Unity Memory Leak Skinning Bug in on and off animation

Discussion in 'Animation' started by PeppNGo, Jan 12, 2024.

  1. PeppNGo

    PeppNGo

    Joined:
    Dec 28, 2016
    Posts:
    10
    I recently did a puppet bone skin in Unity. It works, but I notice if I have an on and off object (in this case the wing flap goes from up to down and one set turns off while the other turns on when flapping) it causes a memory leak. If I remove this on and off switching sprite feature in the animation, the problem goes away. I put a video to show exactly what I am talking about. The scene itself just has the enemy character flapping in it, and nothing else is running except basic Unity things.



    Technical jargon below, feel free not to read as it is long. It is not code but I wrapped it to make it a little easier to view but again it is just an error report. I wanted to report this as it is not due to my scripts.

    Code (csharp):
    1.  
    2. Found 1 leak(s) from callstack:
    3. 0x000001bf5edec95b (Mono JIT Code) Unity.Collections.NativeArray`1<int>:Allocate (int,Unity.Collections.Allocator,Unity.Collections.NativeArray`1<int>&)
    4. 0x000001bf5edec713 (Mono JIT Code) Unity.Collections.NativeArray`1<int>:.ctor (int,Unity.Collections.Allocator,Unity.Collections.NativeArrayOptions)
    5. 0x000001be7f6c30e3 (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkin:CacheBoneTransformIds (bool) (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkin.cs:331)
    6. 0x000001be9fc811e3 (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkin:CopyToSpriteSkinData (UnityEngine.U2D.Animation.SpriteSkinData&,int) (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkin.cs:612)
    7. 0x000001be9fc80f7b (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkinComposite:CopyToSpriteSkinData (int) (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkinComposite.cs:389)
    8. 0x000001be7fc7a68b (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkinComposite:BatchRemoveSpriteSkins () (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkinComposite.cs:680)
    9. 0x000001bf11f68ec3 (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkinComposite:LateUpdate () (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkinComposite.cs:521)
    10. 0x000001bf11f68c33 (Mono JIT Code) UnityEngine.U2D.Animation.SpriteSkinUpdateHelper:LateUpdate () (at ./Library/PackageCache/com.unity.2d.animation@9.1.0/Runtime/SpriteSkinUpdateHelper.cs:30)
    11. 0x000001bf5e9941b8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    12. 0x00007ff8174de0d4 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    13. 0x00007ff81741eb74 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    14. 0x00007ff81741ed0c (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
    15. 0x00007ff7e4ffa034 (Unity) scripting_method_invoke
    16. 0x00007ff7e4fd8254 (Unity) ScriptingInvocation::Invoke
    17. 0x00007ff7e4fbf8f4 (Unity) MonoBehaviour::CallMethodIfAvailable
    18. 0x00007ff7e4fbfa1a (Unity) MonoBehaviour::CallUpdateMethod
    19. 0x00007ff7e4a5af6b (Unity) BaseBehaviourManager::CommonUpdate<LateBehaviourManager>
    20. 0x00007ff7e4a625ea (Unity) LateBehaviourManager::Update
    21. 0x00007ff7e4c930ed (Unity) `InitPlayerLoopCallbacks'::`2'::PreLateUpdateScriptRunBehaviourLateUpdateRegistrator::Forward
    22.  
    23.  
    NOTES:
    Using Unity version: 2022.3.8f1
    Using 2d Animation package 9.1.0, the Jan 12 2024 version. Note that this same issue appeared in the last package I was using too: 9.0.4, the Oct 5 2023 version.

    Also, when I deleted those parts of the animation (the on and off of the wing up and wing down flap) and reanimated it, the problem seems to have fixed itself so far. For some odd reason I needed to just reanimate it again in that specific section of the animation. So the problem appears fixed by doing the animation over.

    UPDATE: I notice the memory leak returns after a while of working and never leaves again.
     
    Last edited: Jan 12, 2024