Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug Index out of range in RigSyncSceneToStream crashes Unity

Discussion in 'Animation Rigging' started by fleity, May 3, 2023.

  1. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    406
    hi everyone,

    I have a project which would love to use anim rigging but we keep running into problems.

    btw Unity 2022.2.13f1, Anim Rigging 1.2.1

    A lot of our logic runs on timelines evaluated in fixed update, we even evaluate the animator graphs from here. Which is a bit odd idk but keep reading:

    To make that setup compatible with animation rigging we use RigBuilder.Build(Animator.playableGraph) to build the graph into the Animators. However apparently there is something terribly wrong here. Because when I disable and reenable a gameobject using the animation rigging package setup this way I get spammed with errors and then the engine crashes entirely.

    I was able to isolate the issue to this callstack

    Code (CSharp):
    1. IndexOutOfRangeException: Index 1 is out of range of '1' Length.
    2. Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <1d5ae28f5ca3488dbddca7794af65eb1>:0)
    3. Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <1d5ae28f5ca3488dbddca7794af65eb1>:0)
    4. Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <1d5ae28f5ca3488dbddca7794af65eb1>:0)
    5. UnityEngine.Animations.Rigging.RigSyncSceneToStreamJob.ProcessAnimation (UnityEngine.Animations.AnimationStream stream) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationJobs/RigSyncSceneToStreamJob.cs:131)
    6. UnityEngine.Animations.ProcessAnimationJobStruct`1[T].Execute (T& data, System.IntPtr animationStreamPtr, System.IntPtr methodIndex, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <db3566faca374d64972d756cf7552385>:0)
    7. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

    this is the function / line mentioned

    "currConstraintWeights *= (currRigWeights[rigIndex] * rigStates[rigIndex]);"

    Code (CSharp):
    1.         public void ProcessAnimation(AnimationStream stream)
    2.         {
    3.             transformSyncer.Sync(ref stream);
    4.             propertySyncer.Sync(ref stream);
    5.             rigWeightSyncer.Sync(ref stream);
    6.             constraintWeightSyncer.Sync(ref stream);
    7.  
    8.             var currRigWeights = rigWeightSyncer.StreamValues(ref stream);
    9.             var currConstraintWeights = constraintWeightSyncer.StreamValues(ref stream);
    10.  
    11.             int rigIndex = 0;
    12.             for (int i = 0, count = currConstraintWeights.Length; i < count; ++i)
    13.             {
    14.                 if (i >= rigConstraintEndIdx[rigIndex])
    15.                     rigIndex++;
    16.  
    17.                 currConstraintWeights[i] *= (currRigWeights[rigIndex] * rigStates[rigIndex]);
    18.             }
    19.  
    20.             AnimationStreamHandleUtility.WriteFloats(stream, modulatedConstraintWeights, currConstraintWeights, false);
    21.         }
    I see the problem, but I have no idea how to fix it / work around it. I'd be thankful for any kind of advice or idea.

    The culprit is very very likely Rigbuilder.Build() because depending on when I call this I can break unity at any given moment.



    Sometimes I can pause unity before it crashes, also found this
    Code (csharp):
    1.  
    2. System.InvalidOperationException: The TransformStreamHandle cannot be resolved.
    3. This Exception was thrown from a job compiled with Burst, which has limited exception support.
    4. 0x00007ffcdd581aaa (b547796dbfbe88451a79b3557ab8309) UnityEngine.Animations.Rigging.AnimationRuntimeUtils.PassThrough (at C:/Projects/Fizbin/pk_main/project kokidon/Library/PackageCache/com.unity.burst@1.8.4/.Runtime/Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/Utils/AnimationRuntimeUtils.cs:395)
    5. 0x00007ffcdd589cfd (b547796dbfbe88451a79b3557ab8309) UnityEngine.Animations.ProcessAnimationJobStruct`1<UnityEngine.Animations.Rigging.ChainIKConstraintJob>.Execute(ref UnityEngine.Animations.Rigging.ChainIKConstraintJob data, System.IntPtr animationStreamPtr, System.IntPtr methodIndex, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_73c04fea4d034adcf3d7ccb459d2c985 from UnityEngine.AnimationModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at C:/Projects/Fizbin/pk_main/project kokidon/Library/PackageCache/com.unity.burst@1.8.4/.Runtime/unknown/unknown:0)
    6. 0x00007ffcdd589a76 (b547796dbfbe88451a79b3557ab8309) f8836ca6e4d6f549d52557a9dcf72086
    7. 0x00007ff7a00a9227 (Unity) ExecuteJobWithSharedJobData
    8. 0x00007ff7a08c5923 (Unity) AnimationScriptPlayable::ProcessAnimation
    9. 0x00007ff7a08c57b9 (Unity) AnimationPlayable::ProcessAnimation
    10. 0x00007ff7a08c583b (Unity) AnimationScriptPlayable::ProcessAnimation
    11. 0x00007ff7a08533b9 (Unity) `anonymous namespace'::ProcessPlayableGraph
    12. 0x00007ff7a0852fbb (Unity) Animator::ProcessAnimationsStep
    13. 0x00007ff7a086ef18 (Unity) UnityEngine::Animation::BlockRangeJob<Animator::AnimatorJob>::Job
    14. 0x00007ff7a00a5eff (Unity) ujob_execute_job
    15. 0x00007ff7a00a72cf (Unity) ujob_wait_for
    16. 0x00007ff7a00a1ca7 (Unity) CompleteFenceInternal
    17. 0x00007ff7a087883a (Unity) Animator::UpdateAvatars
    18. 0x00007ff7a03f8ea4 (Unity) PlayableGraph::Evaluate
    19. 0x00007ff79f631b0c (Unity) PlayableGraph_CUSTOM_Evaluate_Injected
    20. 0x000001bd19956e8f (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Playables.PlayableGraph:Evaluate_Injected (UnityEngine.Playables.PlayableGraph&,single)
    21. 0x000001bd19956db3 (Mono JIT Code) UnityEngine.Playables.PlayableGraph:Evaluate (single)
    22. 0x000001bd1995275b (Mono JIT Code) PK.Gameplay.Character.Common.Clips.AnimatorMixerBehaviour:PlayClip (UnityEngine.Playables.Playable,UnityEngine.Playables.FrameData) (at C:/Projects/Fizbin/pk_main/project kokidon/Assets/Source/Gameplay/Character/Common/Clips/AnimatorTrack/AnimatorMixerBehaviour.cs:164)
    23. 0x000001bd1994f579 (Mono JIT Code) PK.Gameplay.Character.Common.Clips.BaseBehaviour:ProcessFrame (UnityEngine.Playables.Playable,UnityEngine.Playables.FrameData,object) (at C:/Projects/Fizbin/pk_main/project kokidon/Assets/Source/Gameplay/Character/Common/Clips/BaseBehaviour.cs:89)
    24. 0x000001bd1994f82b (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___Playable_FrameData_object (object,intptr,intptr,intptr)
    25. 0x00007ffcce140394 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    26. 0x00007ffcce07eb44 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    27. 0x00007ffcce07ecdc (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
    28. 0x00007ff7a047d7b4 (Unity) scripting_method_invoke
    29. 0x00007ff7a045e0e4 (Unity) ScriptingInvocation::Invoke
    30. 0x00007ff7a03ff01b (Unity) PlayableMethods::InvokeProcessFrame
    31. 0x00007ff7a03f38e0 (Unity) Playable::Process
    32. 0x00007ff79fffbe1c (Unity) Playable::ProcessVisitor
    33. 0x00007ff79fffc288 (Unity) PostOrderPlayableTraverser::Traverse
    34. 0x00007ff79fffbedb (Unity) PostOrderPlayableTraverser::RecursiveVisit
    35. 0x00007ff79fffc19c (Unity) PostOrderPlayableTraverser::Traverse
    36. 0x00007ff7a03fcfa3 (Unity) ScriptPlayableOutput::ScriptProcessFrame
    37. 0x00007ff7a03f8ea4 (Unity) PlayableGraph::Evaluate
    38. 0x00007ff79f631b0c (Unity) PlayableGraph_CUSTOM_Evaluate_Injected
    39. 0x000001bd19956e8f (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Playables.PlayableGraph:Evaluate_Injected (UnityEngine.Playables.PlayableGraph&,single)
    40. 0x000001bd19956db3 (Mono JIT Code) UnityEngine.Playables.PlayableGraph:Evaluate (single)
    41. 0x000001bd9f8aca1b (Mono JIT Code) PK.Gameplay.Character.Common.Clips.PlayableDirectorController:FixedUpdate () (at C:/Projects/Fizbin/pk_main/project kokidon/Assets/Source/Gameplay/Character/Common/Clips/PlayableDirectorController.cs:132)
    42. 0x000001bda0c07a88 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    43. 0x00007ffcce140394 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    44. 0x00007ffcce07eb44 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    45. 0x00007ffcce07ecdc (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
    46. 0x00007ff7a047d7b4 (Unity) scripting_method_invoke
    47. 0x00007ff7a045e0e4 (Unity) ScriptingInvocation::Invoke
    48. 0x00007ff7a0445a54 (Unity) MonoBehaviour::CallMethodIfAvailable
    49. 0x00007ff7a0445b7a (Unity) MonoBehaviour::CallUpdateMethod
    50. 0x00007ff79fee6b2b (Unity) BaseBehaviourManager::CommonUpdate<FixedBehaviourManager>
    51. 0x00007ff79feee39a (Unity) FixedBehaviourManager::Update
    52. 0x00007ff7a0114116 (Unity) `InitPlayerLoopCallbacks'::`2'::FixedUpdateScriptRunBehaviourFixedUpdateRegistrator::Forward
    53. 0x00007ff7a00fb65a (Unity) ExecutePlayerLoop
    54. 0x00007ff7a00fb7e3 (Unity) ExecutePlayerLoop
    55. 0x00007ff7a0101b45 (Unity) PlayerLoop
    56. 0x00007ff7a10937af (Unity) PlayerLoopController::InternalUpdateScene
    57. 0x00007ff7a10a04ed (Unity) PlayerLoopController::UpdateSceneIfNeededFromMainLoop
    58. 0x00007ff7a109e7f1 (Unity) Application::TickTimer
    59. 0x00007ff7a152a68a (Unity) MainMessageLoop
    60. 0x00007ff7a152f430 (Unity) WinMain
    61. 0x00007ff7a291272e (Unity) __scrt_common_main_seh
    62. 0x00007ffd8f5b269d (KERNEL32) BaseThreadInitThunk
    63. 0x00007ffd90a4a9f8 (ntdll) RtlUserThreadStart
    64. [/I]
    65.  

    burst disabled
    Code (csharp):
    1.  
    2. InvalidOperationException: The TransformStreamHandle cannot be resolved.
    3. UnityEngine.Animations.TransformStreamHandle.CheckIsValidAndResolve (UnityEngine.Animations.AnimationStream& stream) (at <db3566faca374d64972d756cf7552385>:0)
    4. UnityEngine.Animations.TransformStreamHandle.GetLocalTRS (UnityEngine.Animations.AnimationStream stream, UnityEngine.Vector3& position, UnityEngine.Quaternion& rotation, UnityEngine.Vector3& scale) (at <db3566faca374d64972d756cf7552385>:0)
    5. UnityEngine.Animations.Rigging.ReadWriteTransformHandle.GetLocalTRS (UnityEngine.Animations.AnimationStream stream, UnityEngine.Vector3& position, UnityEngine.Quaternion& rotation, UnityEngine.Vector3& scale) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationJobs/TransformHandle.cs:38)
    6. UnityEngine.Animations.Rigging.AnimationRuntimeUtils.PassThrough (UnityEngine.Animations.AnimationStream stream, UnityEngine.Animations.Rigging.ReadWriteTransformHandle handle) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/Utils/AnimationRuntimeUtils.cs:393)
    7. UnityEngine.Animations.Rigging.ChainIKConstraintJob.ProcessAnimation (UnityEngine.Animations.AnimationStream stream) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationJobs/ChainIKConstraintJob.cs:93)
    8. UnityEngine.Animations.ProcessAnimationJobStruct`1[T].Execute (T& data, System.IntPtr animationStreamPtr, System.IntPtr methodIndex, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <db3566faca374d64972d756cf7552385>:0)
    9. UnityEngine.Playables.PlayableGraph:Evaluate(Single)
    10. PK.Gameplay.Character.Common.Clips.AnimatorMixerBehaviour:PlayClip(Playable, FrameData) (at Assets/Source/Gameplay/Character/Common/Clips/AnimatorTrack/AnimatorMixerBehaviour.cs:163)
    11. PK.Gameplay.Character.Common.Clips.BaseBehaviour:ProcessFrame(Playable, FrameData, Object) (at Assets/Source/Gameplay/Character/Common/Clips/BaseBehaviour.cs:86)
    12. UnityEngine.Playables.PlayableGraph:Evaluate(Single)
    13. PK.Gameplay.Character.Common.Clips.PlayableDirectorController:FixedUpdate() (at Assets/Source/Gameplay/Character/Common/Clips/PlayableDirectorController.cs:130)
    14. [/I]
    15.  

    on domain reload:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. UnityEngine.Animations.Rigging.RigUtils.ExtractAllSyncableData (UnityEngine.Animator animator, System.Collections.Generic.IList`1[T] layers, System.Collections.Generic.List`1[UnityEngine.Transform]& syncableTransforms, System.Collections.Generic.List`1[UnityEngine.Animations.Rigging.SyncableProperties]& syncableProperties) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/RigUtils.cs:188)
    4. UnityEngine.Animations.Rigging.RigUtils.CreateSyncSceneToStreamData (UnityEngine.Animator animator, System.Collections.Generic.IList`1[T] layers) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/RigUtils.cs:328)
    5. UnityEngine.Animations.Rigging.SyncSceneToStreamLayer.Initialize (UnityEngine.Animator animator, System.Collections.Generic.IList`1[T] layers) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/SyncSceneToStreamLayer.cs:21)
    6. UnityEngine.Animations.Rigging.RigBuilderUtils.BuildPlayables (UnityEngine.Animator animator, UnityEngine.Playables.PlayableGraph graph, System.Collections.Generic.IList`1[T] layers, UnityEngine.Animations.Rigging.SyncSceneToStreamLayer syncSceneToStreamLayer) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/RigBuilderUtils.cs:58)
    7. UnityEngine.Animations.Rigging.RigBuilderUtils.BuildPlayableGraph (UnityEngine.Playables.PlayableGraph graph, UnityEngine.Animator animator, System.Collections.Generic.IList`1[T] layers, UnityEngine.Animations.Rigging.SyncSceneToStreamLayer syncSceneToStreamLayer) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/RigBuilderUtils.cs:84)
    8. UnityEngine.Animations.Rigging.RigBuilder.Build (UnityEngine.Playables.PlayableGraph graph) (at ./Library/PackageCache/com.unity.animation.rigging@1.2.1/Runtime/AnimationRig/RigBuilder.cs:172)
    9. PK.Gameplay.Character.Common.Clips.AnimatorMixerBehaviour.PlayClip (UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info) (at Assets/Source/Gameplay/Character/Common/Clips/AnimatorTrack/AnimatorMixerBehaviour.cs:149)
    10. PK.Gameplay.Character.Common.Clips.BaseBehaviour.ProcessFrame (UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info, System.Object playerData) (at Assets/Source/Gameplay/Character/Common/Clips/BaseBehaviour.cs:86)
    11. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    12. [/I]
    13.  
     
    Last edited: May 4, 2023