Navmesh Cut - Invalid Allocation Exception

Version Info

Unity Version: 6000.0.32f1
Astar Version: 5.2.2

Summary

I remove the SimulatedMovement component on my entity to stop the pathfinding and move it off the navmesh. Then when I place Navmesh Cuts nearby it would randomly start throwing this invalid allocation repeatedly, in a build it crashes.

After digging through the code I noticed that the RVOSystem doesn’t reference SimulatedMovement and is still running when it’s removed. In my case I didn’t need it to run when SimulatedMovement wasn’t present, so my workaround was to disable ManagedState.enableLocalAvoidance for any entity without SimulatedMovement.

I suspect that it’s caused by something that RVOSystem relies on not being updated when SimulatedMovement isn’t present. Maybe the node it was on when SimulatedMovement was removed is being deleted by Navmesh cut… Just speculation :man_shrugging:

Error

System.IndexOutOfRangeException: Invalid allocation -2
This Exception was thrown from a job compiled with Burst, which has limited exception support.
0x00007fface1afcee (Unity) burst_abort
0x00007ffac88597fe (a8d9c6aea336e94cef6a1d7cccf8a3f) burst_Abort_Trampoline
0x00007ffac87852aa (a8d9c6aea336e94cef6a1d7cccf8a3f) Pathfinding.Collections.SlabAllocator`1<int>.GetSpan (at E:/Unity/AutomationECS/Library/PackageCache/com.unity.burst/.Runtime/Packages/com.arongranberg.astar/Core/Collections/SlabAllocator.cs:118)
0x00007ffac8789761 (a8d9c6aea336e94cef6a1d7cccf8a3f) Pathfinding.NavmeshEdges.NavmeshBorderData.GetHierarchicalNodesInRangeRec (at E:/Unity/AutomationECS/Library/PackageCache/com.unity.burst/.Runtime/Packages/com.arongranberg.astar/Core/Misc/NavmeshEdges.cs:305)
0x00007ffac87a7cd0 (a8d9c6aea336e94cef6a1d7cccf8a3f) Pathfinding.RVO.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.GenerateObstacleVOs (at E:/Unity/AutomationECS/Library/PackageCache/com.unity.burst/.Runtime/Packages/com.arongranberg.astar/Core/RVO/RVOAgentBurst.cs:757)
0x00007ffac87a3703 (a8d9c6aea336e94cef6a1d7cccf8a3f) Pathfinding.RVO.JobRVO`1<Pathfinding.RVO.XZMovementPlane>.ExecuteORCA (at E:/Unity/AutomationECS/Library/PackageCache/com.unity.burst/.Runtime/Packages/com.arongranberg.astar/Core/RVO/RVOAgentBurst.cs:1194)
0x00007ffac87a1436 (a8d9c6aea336e94cef6a1d7cccf8a3f) Pathfinding.Jobs.JobParallelForBatchedExtensions.ParallelForBatchJobStruct`1<Pathfinding.RVO.JobRVO`1<Pathfinding.RVO.XZMovementPlane>>.Execute(ref Pathfinding.RVO.JobRVO`1<Pathfinding.RVO.XZMovementPlane> jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_a6b13d6cf2f188641a365ab636459df1 from AstarPathfindingProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at E:/Unity/AutomationECS/Library/PackageCache/com.unity.burst/.Runtime/Packages/com.arongranberg.astar/Utilities/IJobParallelForBatched.cs:42)
0x00007ffac87a02cd (a8d9c6aea336e94cef6a1d7cccf8a3f) 82cbe6c0c10a60340fd2850c60245b29
0x00007fface1ac3c5 (Unity) ExecuteJob
0x00007fface1ac6ee (Unity) ExecuteJobCopyData
0x00007fface1a98e6 (Unity) ujob_execute_job
0x00007fface1a8a9f (Unity) lane_guts
0x00007fface1ab714 (Unity) worker_thread_routine
0x00007fface3a157d (Unity) Thread::RunThreadWrapper
0x00007ffb520f7374 (KERNEL32) BaseThreadInitThunk
0x00007ffb5351cc91 (ntdll) RtlUserThreadStart

Workaround

Only if you don’t need RVO on the entity that’s stopped.

foreach (var managedState in SystemAPI.Query<ManagedState>().WithNone<SimulateMovement>())
        {
            if (managedState != null && managedState.enableLocalAvoidance)
            {
                managedState.enableLocalAvoidance = false;
            }
        }
1 Like

Good find, thanks for reporting it! Letting @aron_granberg know :+1:

Hi

Thanks. I didn’t manage to replicate the crash. But I did fix the case where stale data could get propagated to the RVOSystem. I’ll include a fix in the next update.

1 Like