Beta - jobs index out of range exception

Using the beta with unity 2022.3.3f1

I’m not entirely sure when this happens… but thought I should get it reported for now.

Error:

System.IndexOutOfRangeException: Invalid allocation 
This Exception was thrown from a job compiled with Burst, which has limited exception support.
0x00007fff03acc88f (4e87570f2f6235e0fc8fd80df0947bd) Pathfinding.NavmeshEdges.NavmeshEdgeData.GetHierarchicalNodesInRangeRec (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Misc/NavmeshEdges.cs:242)
0x00007fff03ad2808 (4e87570f2f6235e0fc8fd80df0947bd) Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.GenerateObstacleVOs (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:825)
0x00007fff03acdf44 (4e87570f2f6235e0fc8fd80df0947bd) Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.ExecuteORCA (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:1247)
0x00007fff03acc286 (4e87570f2f6235e0fc8fd80df0947bd) Pathfinding.Jobs.JobParallelForBatchedExtensions.ParallelForBatchJobStruct`1<Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>>.Execute(ref Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane> jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_19a2719edc7e6beb0903d07cc1403f83 from AstarPathfindingProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.76/Utilities/IJobParallelForBatched.cs:42)
0x00007fff03aca6b6 (4e87570f2f6235e0fc8fd80df0947bd) 906909cd62835d28eb9a35bbf6591c6e
0x00007ff6fc4e5fdc (Unity) ExecuteJob
0x00007ff6fc4e6344 (Unity) ExecuteJobCopyData
0x00007ff6fc4e705f (Unity) ForwardJobForEachToManaged
0x00007ff6fc4e322e (Unity) ujob_execute_job
0x00007ff6fc4e26e4 (Unity) lane_guts
0x00007ff6fc4e5244 (Unity) worker_thread_routine
0x00007ff6fc712977 (Unity) Thread::RunThreadWrapper
0x00007fff35dc7614 (KERNEL32) BaseThreadInitThunk
0x00007fff36e426f1 (ntdll) RtlUserThreadStart

Another series of errors, again not sure what’s triggering these.
NOTE - I have turned off burst compilation as the exceptions cause builds to crash.
This error happened while running in the editor:

IndexOutOfRangeException: Invalid allocation -2
Pathfinding.Util.SlabAllocator`1[T].GetSpan (System.Int32 allocatedIndex) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Collections/SlabAllocator.cs:93)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetHierarchicalNodesInRangeRec (System.Int32 node, UnityEngine.Bounds bounds, Pathfinding.Util.SlabAllocator`1[T] connectionAllocator, Unity.Collections.NativeList`1[T] connectionAllocations, Unity.Collections.NativeList`1[T] nodeBounds, Unity.Collections.NativeList`1[T] indices) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Misc/NavmeshEdges.cs:235)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetObstaclesInRange (System.Int32 hierarchicalNode, UnityEngine.Bounds bounds, Unity.Collections.NativeList`1[T] obstacleIndexBuffer) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Misc/NavmeshEdges.cs:311)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].GenerateObstacleVOs (System.Int32 agentIndex, Unity.Collections.NativeList`1[T] adjacentObstacleIdsScratch, Unity.Collections.NativeArray`1[T] adjacentObstacleVerticesScratch, Unity.Collections.NativeArray`1[T] segmentDistancesScratch, Unity.Collections.NativeArray`1[T] sortedVerticesScratch, Unity.Collections.NativeArray`1[T] orcaLines, Unity.Collections.NativeArray`1[T] orcaLineToAgent, System.Int32& numLines, MovementPlaneWrapper& movementPlane, Unity.Mathematics.float2 optimalVelocity) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:825)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].ExecuteORCA (System.Int32 startIndex, System.Int32 batchSize) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:1246)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].Execute (System.Int32 startIndex, System.Int32 batchSize) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:706)
Pathfinding.Jobs.JobParallelForBatchedExtensions+ParallelForBatchJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Utilities/IJobParallelForBatched.cs:42)

Another version of the invalid allocation error:

IndexOutOfRangeException: Invalid allocation -2
Pathfinding.Util.SlabAllocator`1[T].GetSpan (System.Int32 allocatedIndex) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Collections/SlabAllocator.cs:93)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetHierarchicalNodesInRangeRec (System.Int32 node, UnityEngine.Bounds bounds, Pathfinding.Util.SlabAllocator`1[T] connectionAllocator, Unity.Collections.NativeList`1[T] connectionAllocations, Unity.Collections.NativeList`1[T] nodeBounds, Unity.Collections.NativeList`1[T] indices) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Misc/NavmeshEdges.cs:235)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetObstaclesInRange (System.Int32 hierarchicalNode, UnityEngine.Bounds bounds, Unity.Collections.NativeList`1[T] obstacleIndexBuffer) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/Misc/NavmeshEdges.cs:311)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].GenerateObstacleVOs (System.Int32 agentIndex, Unity.Collections.NativeList`1[T] adjacentObstacleIdsScratch, Unity.Collections.NativeArray`1[T] adjacentObstacleVerticesScratch, Unity.Collections.NativeArray`1[T] segmentDistancesScratch, Unity.Collections.NativeArray`1[T] sortedVerticesScratch, Unity.Collections.NativeArray`1[T] orcaLines, Unity.Collections.NativeArray`1[T] orcaLineToAgent, System.Int32& numLines, MovementPlaneWrapper& movementPlane, Unity.Mathematics.float2 optimalVelocity) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:825)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].ExecuteORCA (System.Int32 startIndex, System.Int32 batchSize) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:1246)
Pathfinding.RVO.Sampled.JobRVO`1[MovementPlaneWrapper].Execute (System.Int32 startIndex, System.Int32 batchSize) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/RVO/RVOAgentBurst.cs:706)
Pathfinding.Jobs.JobParallelForBatchedExtensions+ParallelForBatchJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Utilities/IJobParallelForBatched.cs:42)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete()
Unity.Entities.ComponentDependencyManager:CompleteReadAndWriteDependencyNoChecks(TypeIndex) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentDependencyManager.cs:356)
Unity.Entities.ComponentDependencyManager:CompleteReadAndWriteDependency(TypeIndex) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentDependencyManager.cs:370)
Unity.Entities.EntityManager:CompleteDependencyBeforeRW() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/EntityManager.cs:4488)
Pathfinding.ECS.IFE_1099081274_0:CompleteDependencyBeforeRW(SystemState&) (at ./Unity.Entities.SourceGen.SystemGenerator/Unity.Entities.SourceGen.SystemGenerator.SystemGenerator/Temp/GeneratedCode/AstarPathfindingProject/MovementPlaneFromGraphSystem__System_5938790100.g.cs:219)
Pathfinding.ECS.MovementPlaneFromGraphSystem:OnUpdate(SystemState&) (at ./Library/PackageCache/com.arongranberg.astar@4.3.76/Core/ECS/Systems/MovementPlaneFromGraphSystem.cs:54)
Pathfinding.ECS.MovementPlaneFromGraphSystem:__codegen__OnUpdate(IntPtr, IntPtr)
Unity.Entities.SystemBaseRegistry:ForwardToManaged(IntPtr, SystemState*, Void*) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/SystemBaseRegistry.cs:371)
Unity.Entities.SystemBaseRegistry:CallForwardingFunction(SystemState*, UnmanagedSystemFunctionType) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/SystemBaseRegistry.cs:340)
Unity.Entities.SystemBaseRegistry:CallOnUpdate(SystemState*) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/SystemBaseRegistry.cs:383)
Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate$BurstManaged(Void*) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:855)
Unity.Entities.UnmanagedUpdate_0000158C$BurstDirectCall:Invoke(Void*)
Unity.Entities.WorldUnmanagedImpl:UnmanagedUpdate(Void*) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:828)
Unity.Entities.WorldUnmanagedImpl:UpdateSystem(SystemHandle) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:894)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentSystemGroup.cs:729)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentSystemGroup.cs:699)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentSystemGroup.cs:735)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ComponentSystemGroup.cs:693)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/SystemBase.cs:418)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)

NOTE these seem to happen consistently when I do a runtime graph update. For example I place a building which does a graph update on those bounds, each time I get dozens of those allocation errors.

Hi

Thank you!
Which version of the package are you using? Does it happen with the latest beta version?
If you have a scene in which you can replicate this issue and that you are willing to share with me, or some other way for me to replicate the issue, that would be much appreciated.

Yes still happening in unity 2022.3.5f1/astar 4.3.79.

Unlikely I can give you a scene to test with as this happens in my main gameplay scene in a 100GB project.

It does appear to be happening when doing graph updates with bounds around objects.
For example my agents cut down trees. When the tree falls and has stopped rolling around, my code does a graph update so the tree trunk is cut out.
It also does graph updates as the agent cuts logs from the trunk (the cut out of the remaining tree is smaller and smaller).

Here you can see the logs that have been spawned as the tree was bucked, and the remaining part of the tree that still creates a cutout on graph updates.


When this happens I get a dozen or more errors like this:

System.IndexOutOfRangeException: Invalid allocation 
This Exception was thrown from a job compiled with Burst, which has limited exception support.
0x00007ffcb82fc88f (45353208aab3ccc237b982185db9a65) Pathfinding.NavmeshEdges.NavmeshEdgeData.GetHierarchicalNodesInRangeRec (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.79/Core/Misc/NavmeshEdges.cs:242)
0x00007ffcb8302808 (45353208aab3ccc237b982185db9a65) Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.GenerateObstacleVOs (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.79/Core/RVO/RVOAgentBurst.cs:825)
0x00007ffcb82fdf44 (45353208aab3ccc237b982185db9a65) Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.ExecuteORCA (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.79/Core/RVO/RVOAgentBurst.cs:1247)
0x00007ffcb82fc286 (45353208aab3ccc237b982185db9a65) Pathfinding.Jobs.JobParallelForBatchedExtensions.ParallelForBatchJobStruct`1<Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane>>.Execute(ref Pathfinding.RVO.Sampled.JobRVO`1<Pathfinding.RVO.XZMovementPlane> jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_8633849924189afc0e68e8607bb27842 from AstarPathfindingProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at D:/__UnityProjects/SOI_2020.3.8f1_LTS_v2021/SOI_2020.3.8f1_LTS_v2021/Library/PackageCache/com.unity.burst@1.8.7/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.79/Utilities/IJobParallelForBatched.cs:42)
0x00007ffcb82fa6b6 (45353208aab3ccc237b982185db9a65) 906909cd62835d28eb9a35bbf6591c6e
0x00007ff6e2f1c8bc (Unity) ExecuteJob
0x00007ff6e2f1cc24 (Unity) ExecuteJobCopyData
0x00007ff6e2f1d93f (Unity) ForwardJobForEachToManaged
0x00007ff6e2f19b0e (Unity) ujob_execute_job
0x00007ff6e2f18fc4 (Unity) lane_guts
0x00007ff6e2f1bb24 (Unity) worker_thread_routine
0x00007ff6e31489a7 (Unity) Thread::RunThreadWrapper
0x00007ffd8e3b7614 (KERNEL32) BaseThreadInitThunk
0x00007ffd8e9a26b1 (ntdll) RtlUserThreadStart

Again these cause crashes in builds with burst compilation on which is a show stopper for using followerEntity.

Unity version 2023.1.0f1, package version 4.3.84

I’ve just updated to the latest version of the beta, and it seems like this issue is still happening. I haven’t been able to reproduce it in a simpler scene, but it definitely seems to have something to do with graph update scenes and navmeshcuts with a recast navmesh and FollowerEntities.

I’m cutting a circle around stationary agents (with IsDual enabled) and applying a GraphUpdateScene to change the tags of the nodes inside the cut to cause other agents to avoid the area (kind of like a local avoidance behaviour). Recreating a similar setup in a different scene doesn’t seem to cause the issue, but when it happens in my main scene it’s exactly the same “Invalid allocation -2” issue as above.

Oh ho, scratch that, I’ve gotten it to happen in a test scene.

image
image

The scene consists of:

  • A plane
  • The pathfinder with a single recast navmesh, the settings unchanged from default
  • An empty gameobject with the FollowerEntity component on it, the settings unchanged from default
  • An empty gameobject with a GraphUpdateScene and a custom navmeshcut component:
public class NavmeshCutGraphUpdate : NavmeshCut
{
    protected GraphUpdateScene _update;
    protected override void Awake()
    {
        _update = GetComponent<GraphUpdateScene>();
        base.Awake();
    }

    public override void UsedForCut()
    {
        base.UsedForCut();
        _update.Apply();
    }
}

The error occurs whenever the NavmeshCut is applied (whether by enabling the component or moving it around).

As an interesting note, simply disabling the FollowerEntity component and re-enabling it causes the error to no longer occur. However, the error comes back if the FollowerEntity gameobject is duplicated, even from this “fixed” state.

The exact error I’m getting is:

IndexOutOfRangeException: Invalid allocation -2
Pathfinding.Util.SlabAllocator`1[T].GetSpan (System.Int32 allocatedIndex) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Collections/SlabAllocator.cs:93)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetHierarchicalNodesInRangeRec (System.Int32 node, UnityEngine.Bounds bounds, Pathfinding.Util.SlabAllocator`1[T] connectionAllocator, Unity.Collections.NativeList`1[T] connectionAllocations, Unity.Collections.NativeList`1[T] nodeBounds, Unity.Collections.NativeList`1[T] indices) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Misc/NavmeshEdges.cs:295)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetObstaclesInRange (System.Int32 hierarchicalNode, UnityEngine.Bounds bounds, Unity.Collections.NativeList`1[T] obstacleIndexBuffer) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Misc/NavmeshEdges.cs:377)
Pathfinding.NavmeshEdges+NavmeshEdgeData.GetEdgesInRange (System.Int32 hierarchicalNode, UnityEngine.Bounds localBounds, Unity.Collections.NativeList`1[T] edgeBuffer, Pathfinding.Util.NativeMovementPlane movementPlane) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/Misc/NavmeshEdges.cs:384)
Pathfinding.ECS.FollowerControlSystem+ControlJob.Execute (Unity.Transforms.LocalTransform& transform, Pathfinding.ECS.MovementState& state, Pathfinding.ECS.DestinationPoint& destination, Pathfinding.ECS.AgentCylinderShape& shape, Pathfinding.ECS.AgentMovementPlane& movementPlane, Pathfinding.ECS.MovementSettings& settings, Pathfinding.ECS.ResolvedMovement& resolvedMovement, Pathfinding.ECS.MovementControl& controlOutput) (at ./Library/PackageCache/com.arongranberg.astar@4.3.84/Core/ECS/Systems/FollowerControlSystem.cs:266)
Pathfinding.ECS.FollowerControlSystem+ControlJob.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 chunkIndexInQuery, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) (at ./Unity.Entities.SourceGen.JobEntityGenerator/Unity.Entities.SourceGen.JobEntity.JobEntityGenerator/Temp/GeneratedCode/AstarPathfindingProject/FollowerControlSystem__JobEntity_9809413830.g.cs:55)
Pathfinding.ECS.FollowerControlSystem+ControlJob.Unity.Entities.IJobChunk.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 unfilteredChunkIndex, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) <0x1c7c53cb250 + 0x00072> in <4ae258a57e2c4541b6ad89f791e94a02>:0
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities/IJobChunk.cs:416)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities/IJobChunk.cs:363)

1 Like

Hmm.

I think I know what this is caused by. It’s a bit tricky to fix, but I’ll work on it.

1 Like