Crash JobParallelForBatchProducer

Hi Aaron!

I sometimes get crashes when loading player saves. At this point, a lot of objects are created that either cut off the navmesh below them or generate it above them.

After reading a few topics, I assumed it was due to a data race when using threads. I switched the settings to update in a non-threaded coroutine. Unfortunately, this did not help.
How can I fix this? Are there any rules to follow when dealing with a lot of objects? Or do I need to fine-tune the A* settings?

  • A* version: 5.0.2
  • Unity version: 2022.3.16f1
NullReferenceException: Object reference not set to an instance of an object
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00024] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in <9fade6610f4a492a86602edcaed0e6d8>:0 
  at (wrapper delegate-invoke) Unity.Jobs.IJobExtensions+JobStruct`1+ExecuteJobFunction[Pathfinding.HierarchicalGraph+JobRecalculateComponents].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.HierarchicalGraph/JobRecalculateComponents&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

NullReferenceException: Object reference not set to an instance of an object
  at Pathfinding.NavmeshEdges+JobCalculateObstacles.CalculateObstacles (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.Util.SlabAllocator`1[T] obstacleVertexGroups, Pathfinding.Util.SlabAllocator`1[T] obstacleVertices, Unity.Collections.NativeArray`1[T] obstacles, Unity.Collections.NativeList`1[T] edgesScratch) [0x000b6] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Pathfinding.NavmeshEdges+JobCalculateObstacles.Execute (System.Int32 startIndex, System.Int32 count) [0x00074] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x0000f] in <ddcff769129b448e969cc1bc72b4a07a>:0 
  at (wrapper delegate-invoke) Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer`1+ExecuteJobFunction[Pathfinding.NavmeshEdges+JobCalculateObstacles].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

IndexOutOfRangeException: Index was outside the bounds of the array.
  at Pathfinding.Graphs.Navmesh.NavmeshTile.GetVertex (System.Int32 index) [0x00019] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Pathfinding.NavmeshBase.GetVertex (System.Int32 index) [0x0000b] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Pathfinding.TriangleMeshNode.GetVertices (Pathfinding.Int3& v0, Pathfinding.Int3& v1, Pathfinding.Int3& v2) [0x0000c] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Pathfinding.NavmeshEdges+JobCalculateObstacles.CalculateBoundingBox (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode) [0x00066] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Pathfinding.NavmeshEdges+JobCalculateObstacles.Execute (System.Int32 startIndex, System.Int32 count) [0x0006b] in <4537c686c0d9405a89b5e12be0e24066>:0 
  at Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x0000f] in <ddcff769129b448e969cc1bc72b4a07a>:0 
  at (wrapper delegate-invoke) Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer`1+ExecuteJobFunction[Pathfinding.NavmeshEdges+JobCalculateObstacles].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)



Not sure the exact cause of the issue, but I might have a solution. Try adjusting your loading to be complete before Astar ever runs. Might just have to disable Astar until loading is done, or do something with additive scenes.

Hi

Are you getting this error in the editor or in a build? If so, is it IL2CPP?
Would it be possible for you to upgrade to a newer version of Unity? There have been some issues with buggy IL2CPP compilation in older versions of Unity.

Hi
We were thinking in this direction, but the day before yesterday the game crashed right during gameplay, not during loading. It seems that the problem is much more global…

Hi

The error appears in the Mono build. We are currently unable to update to a new version, but we may have to do so if there are no other options.

The player also shared logs containing STACK TRACE OUTPUT. Perhaps this will help find the cause.

0x00007FF938CCF96A (lib_burst_generated) burst.initialize.statics.ec4e7118baaece369b657d12d7bf8bc5_avx2

0x00007FF938CCF6F3 (lib_burst_generated) burst.initialize.statics.ec4e7118baaece369b657d12d7bf8bc5_avx2

0x00007FF938D2463B (lib_burst_generated) ec4e7118baaece369b657d12d7bf8bc5

0x00000212110BA495 (Mono JIT Code) (wrapper managed-to-native) Pathfinding.RVO.RVOObstacleCache/Pathfinding.RVO.TraceContours_00000EC1$BurstDirectCall:wrapper_native_indirect_00000212E0D289F0 (intptr&,Pathfinding.Util.UnsafeSpan`1<Pathfinding.RVO.RVOObstacleCache/ObstacleSegment>&,Pathfinding.Util.NativeMovementPlane&,int,Pathfinding.RVO.UnmanagedObstacle*,Pathfinding.Util.SlabAllocator`1<Unity.Mathematics.float3>&,Pathfinding.Util.SlabAllocator`1<Pathfinding.RVO.ObstacleVertexGroup>&,Pathfinding.Jobs.SpinLock&)

0x00000212110B7553 (Mono JIT Code) Pathfinding.RVO.RVOObstacleCache/Pathfinding.RVO.TraceContours_00000EC1$BurstDirectCall:Invoke (Pathfinding.Util.UnsafeSpan`1<Pathfinding.RVO.RVOObstacleCache/ObstacleSegment>&,Pathfinding.Util.NativeMovementPlane&,int,Pathfinding.RVO.UnmanagedObstacle*,Pathfinding.Util.SlabAllocator`1<Unity.Mathematics.float3>&,Pathfinding.Util.SlabAllocator`1<Pathfinding.RVO.ObstacleVertexGroup>&,Pathfinding.Jobs.SpinLock&)

0x00000212110B7433 (Mono JIT Code) Pathfinding.RVO.RVOObstacleCache:TraceContours (Pathfinding.Util.UnsafeSpan`1<Pathfinding.RVO.RVOObstacleCache/ObstacleSegment>&,Pathfinding.Util.NativeMovementPlane&,int,Pathfinding.RVO.UnmanagedObstacle*,Pathfinding.Util.SlabAllocator`1<Unity.Mathematics.float3>&,Pathfinding.Util.SlabAllocator`1<Pathfinding.RVO.ObstacleVertexGroup>&,Pathfinding.Jobs.SpinLock&)

0x00000212110B42EB (Mono JIT Code) Pathfinding.NavmeshEdges/JobCalculateObstacles:CalculateObstacles (Pathfinding.HierarchicalGraph,int,Pathfinding.Util.SlabAllocator`1<Pathfinding.RVO.ObstacleVertexGroup>,Pathfinding.Util.SlabAllocator`1<Unity.Mathematics.float3>,Unity.Collections.NativeArray`1<Pathfinding.RVO.UnmanagedObstacle>,Unity.Collections.NativeList`1<Pathfinding.RVO.RVOObstacleCache/ObstacleSegment>)

0x00000212110AE9EB (Mono JIT Code) Pathfinding.NavmeshEdges/JobCalculateObstacles:Execute (int,int)

0x00000212110AE45B (Mono JIT Code) Unity.Jobs.IJobParallelForBatchExtensions/JobParallelForBatchProducer`1<Pathfinding.NavmeshEdges/JobCalculateObstacles>:Execute (Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

0x00000212110AE59A (Mono JIT Code) (wrapper delegate-invoke) Unity.Jobs.IJobParallelForBatchExtensions/JobParallelForBatchProducer`1/ExecuteJobFunction<Pathfinding.NavmeshEdges/JobCalculateObstacles>:invoke_void_T&_intptr_intptr_JobRanges&_int (Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

0x00000212110AE316 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void__this___intptr&_intptr_intptr_intptr&_int (object,intptr,intptr,intptr)

0x00007FF8D57D4B7E (mono-2.0-bdwgc) mono_jit_set_domain

0x00007FF8D570D204 (mono-2.0-bdwgc) mono_object_get_virtual_method

0x00007FF8D570D37C (mono-2.0-bdwgc) mono_runtime_invoke

What version of Collections are you using? I remember something awhile ago with Astar required me to upgrade it to latest. Might be worth trying to update the Unity packages before going for a full version change.

We are using Collections version 2.1.4.

I think this is likely due to an old unity version. I have seen similar errors that have been resolved by people upgrading to a newer version of Unity.

We decided to almost completely remove the AstarPath.active.UpdateGraphs() call to generate the mesh in places where the floor is generated. This helped reduce the number of crashes. Now we only have one place with a call to AstarPath.active.UpdateGraphs(), and the rest of the mesh is modified via NavmeshCut.

I also found a thread: GraphUpdate & NavmeshCut interaction causing errors
Maybe this is also related to a multi-thread race?

In a few months we will update the Unity version and the collections version, hopefully this will help.

1 Like