AssertionException & Null Reference in HierachicalGraph

Hi Aron, I am occasionally getting some errors. If you recall my game has modifiable terrain and I am calling update graph frequently when the player is editing it.

I am using Beta v 4.3.90
Unity 2022.3.13f1
Burst: 1.8.9
Collections: 2.2.1

I’m also using the ASTAR_RECAST_BFS optimisation define

AssertionException: Assertion failure. Values are equal.
Expected: -2 != -2
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <30adf90198bc4c4b83910c6fb1877998>:0)
UnityEngine.Assertions.Assert.AreNotEqual[T] (T expected, T actual, System.String message, System.Collections.Generic.IEqualityComparer1[T] comparer) (at <30adf90198bc4c4b83910c6fb1877998>:0) UnityEngine.Assertions.Assert.AreNotEqual[T] (T expected, T actual, System.String message) (at <30adf90198bc4c4b83910c6fb1877998>:0) UnityEngine.Assertions.Assert.AreNotEqual (System.Int32 expected, System.Int32 actual) (at <30adf90198bc4c4b83910c6fb1877998>:0) Pathfinding.HierarchicalGraph+JobRecalculateComponents.FindHierarchicalNodeChildren (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.GraphNode startNode) (at ./Library/PackageCache/com.arongranberg.astar@4.3.90/Core/Pathfinding/HierarchicalGraph.cs:450) Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () (at ./Library/PackageCache/com.arongranberg.astar@4.3.90/Core/Pathfinding/HierarchicalGraph.cs:537) Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <30adf90198bc4c4b83910c6fb1877998>:0)

AND…

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () (at ./Library/PackageCache/com.arongranberg.astar@4.3.90/Core/Pathfinding/HierarchicalGraph.cs:503)
Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <30adf90198bc4c4b83910c6fb1877998>:0)

1 Like

Out of curiosity, which operating system and architecture are you running on? In particular, are you using an M1/M2 mac?

AMD 3800X, Windows 11

Hi

Hmm, okay.

Try with the latest beta (4.3.91). If you can still reliably replicate it, I’d be very interested.

1 Like

I just gave it a solid test and it seems to be fixed now! :slight_smile:

1 Like

Unfortunately I hit it again in a recent standalone pc build.

NullReferenceException: Object reference not set to an instance of an object
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00024] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:503
at Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in C:\build\output\unity\unity\Runtime\Jobs\Managed\IJob.cs:58 at (wrapper delegate-invoke) Unity.Jobs.IJobExtensions+JobStruct1+ExecuteJobFunction[Pathfinding.HierarchicalGraph+JobRecalculateComponents].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.HierarchicalGraph/JobRecalculateComponents&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Pathfinding/HierarchicalGraph.cs Line: 503)

NullReferenceException: Object reference not set to an instance of an object
at Pathfinding.NavmeshEdges+JobCalculateObstacles.CalculateObstacles (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.Util.SlabAllocator1[T] obstacleVertexGroups, Pathfinding.Util.SlabAllocator1[T] obstacleVertices, Unity.Collections.NativeArray1[T] obstacles, Unity.Collections.NativeList1[T] edgesScratch) [0x000a8] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\NavmeshEdges.cs:234
at Pathfinding.NavmeshEdges+JobCalculateObstacles.Execute (System.Int32 startIndex, System.Int32 count) [0x00074] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\NavmeshEdges.cs:157
at Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x0000f] in .\Library\PackageCache\com.unity.collections@2.2.1\Unity.Collections\Jobs\IJobParallelForBatch.cs:58 at (wrapper delegate-invoke) Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer1+ExecuteJobFunction[Pathfinding.NavmeshEdges+JobCalculateObstacles].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Misc/NavmeshEdges.cs Line: 234)

Hi

Can you reliably replicate this error?

Not with any obvious consistency.

I tried stress testing it by spamming the terrain edits or placing objects and I wouldn’t get the error. Then just when I think its resolved it happens again. My standalone build crashed when I removed a building part the other day. Checking the Player.log revealed these same errors.

If you’re interested we could debug chat on Discord, I can stream my editor for you and maybe we can identify a particular setup issue or conflict with other systems? It might help you diagnose a bug or at least understand how its being deployed in my game.

Something new though is that tiles of the graph appear in the air.

Another Crash, here’s the key parts in the Player.log if it helps.

IndexOutOfRangeException: Index was outside the bounds of the array.
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.FloodFill (Pathfinding.HierarchicalGraph hGraph) [0x00092] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:481
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00157] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:552
at Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in C:\build\output\unity\unity\Runtime\Jobs\Managed\IJob.cs:58 at (wrapper delegate-invoke) Unity.Jobs.IJobExtensions+JobStruct1+ExecuteJobFunction[Pathfinding.HierarchicalGraph+JobRecalculateComponents].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.HierarchicalGraph/JobRecalculateComponents&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Pathfinding/HierarchicalGraph.cs Line: 481)

IndexOutOfRangeException: Index was outside the bounds of the array.
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.RemoveHierarchicalNode (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, System.Boolean removeAdjacentSmallNodes) [0x0004b] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:310
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.RemoveHierarchicalNode (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, System.Boolean removeAdjacentSmallNodes) [0x00078] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:314
at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00058] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:511
at Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in C:\build\output\unity\unity\Runtime\Jobs\Managed\IJob.cs:58 at (wrapper delegate-invoke) Unity.Jobs.IJobExtensions+JobStruct1+ExecuteJobFunction[Pathfinding.HierarchicalGraph+JobRecalculateComponents].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.HierarchicalGraph/JobRecalculateComponents&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Pathfinding/HierarchicalGraph.cs Line: 310)

NullReferenceException: Object reference not set to an instance of an object
at Pathfinding.NavmeshEdges+JobCalculateObstacles.CalculateObstacles (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.Util.SlabAllocator1[T] obstacleVertexGroups, Pathfinding.Util.SlabAllocator1[T] obstacleVertices, Unity.Collections.NativeArray1[T] obstacles, Unity.Collections.NativeList1[T] edgesScratch) [0x000a8] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\NavmeshEdges.cs:234
at Pathfinding.NavmeshEdges+JobCalculateObstacles.Execute (System.Int32 startIndex, System.Int32 count) [0x00074] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\NavmeshEdges.cs:157
at Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x0000f] in .\Library\PackageCache\com.unity.collections@2.2.1\Unity.Collections\Jobs\IJobParallelForBatch.cs:58 at (wrapper delegate-invoke) Unity.Jobs.IJobParallelForBatchExtensions+JobParallelForBatchProducer1+ExecuteJobFunction[Pathfinding.NavmeshEdges+JobCalculateObstacles].invoke_void_T&_intptr_intptr_JobRanges&_int(Pathfinding.NavmeshEdges/JobCalculateObstacles&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete() (at C:\build\output\unity\unity\Runtime\Jobs\ScriptBindings\JobHandle.bindings.cs:26)
Pathfinding.HierarchicalGraph:RecalculateIfNecessary() (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:564)
Pathfinding.WorkItemProcessor:EnsureValidFloodFill() (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\WorkItemProcessor.cs:268)
Pathfinding.WorkItemProcessor:ProcessWorkItems(Boolean, Boolean) (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\WorkItemProcessor.cs:362)
Pathfinding.WorkItemProcessor:ProcessWorkItemsForUpdate(Boolean) (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Misc\WorkItemProcessor.cs:416)
AstarPath:PerformBlockingActions(Boolean) (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\AstarPath.cs:893)
AstarPath:Update() (at .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\AstarPath.cs:876)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Misc/NavmeshEdges.cs Line: 234)

NullReferenceException: Object reference not set to an instance of an object
at Pathfinding.Util.SlabAllocator1[T].Allocate (System.Int32 nElements) [0x0003f] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Collections\SlabAllocator.cs:193 at Pathfinding.Util.SlabAllocator1[T].Allocate (System.Collections.Generic.List1[T] values) [0x00000] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Collections\SlabAllocator.cs:160 at Pathfinding.HierarchicalGraph+JobRecalculateComponents.FindHierarchicalNodeChildren (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.GraphNode startNode) [0x00123] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:457 at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x000f2] in .\Library\PackageCache\com.arongranberg.astar@4.3.91\Core\Pathfinding\HierarchicalGraph.cs:537 at Unity.Jobs.IJobExtensions+JobStruct1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) [0x00001] in C:\build\output\unity\unity\Runtime\Jobs\Managed\IJob.cs:58
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)

(Filename: ./Library/PackageCache/com.arongranberg.astar@4.3.91/Core/Collections/SlabAllocator.cs Line: 193)

Crash!!!

I just tried another test…

If I stay in the same location and spam the level terrain tool it will be fine, but if I start moving around and start laying a road I will hit the error pretty quickly.

So the ProceduralGraphMover is being told to Update a specific modified tile whilst also updating the graph edge tiles as the target moves.

Here’s a video, the error throws at about 6 seconds into the video.

I really can’t replicate this :confused:

If you have any somewhat reliable way to replicate it, I’d be very happy to check it out.

I can reliably trigger it but I can’t give you a way to repro the issue. I have a fairly advanced world generation system that uses threading. I dropped you a message on Discord, probably the best way to look into it is I can stream my Editor to you on a call and show you how I have integrated it and maybe from that you might see something that stands out.

I appreciate you don’t want to get on a call with everyone that uses your asset but the offer is there if you want to fix it.

Would it be possible for you to share your project with me?

No, sorry I am unable to do that. I have worked with other Asset store devs over Discord before and it is a very effective way to communicate and resolve bugs though.

Hi

Would you mind trying the latest version? I think I have fixed the issue.

1 Like

It seams more stable but I was still able to trip it by spamming terrains edits while moving. The main difference is the error type, it only displayed this error.

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () (at ./Library/PackageCache/com.arongranberg.astar@4.3.95/Core/Pathfinding/HierarchicalGraph.cs:503)
Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <30adf90198bc4c4b83910c6fb1877998>:0)

Hi

Are you modifying any nodes manually? Without calling AstarPath.active.UpdateGraphs, that is?

I think that this is caused by some multithreading race conditions, which are the worst to debug.

No, the only thing I am doing is call UpdateGraphs with a bounding volume. This can happen very frequently if the players is making a lot of terrain edits, several per second.

I’m not an expert at threading but my game uses threading for the terrain mesh/heightmap generation, this only occurs on new terrain tiles, not the one that is being modified since they are applied immediately. It’s using Threads, not Jobs.

I have an idea that might relieve some pressure on AStar. I will add updates into a queue and deque them with a delay. It won’t matter if the nav mesh update has a slight delay of a few frames. I could probably also scan the queue and skip ones that are in the same area and only apply the most recent one.

Again, extending the offer to meet with you on Discord to chat about it.

1 Like

Hi Aron, just bumping this to keep it on your radar, I am still getting null references when updating the recast graph.

@5.0.4\Core\Pathfinding\HierarchicalGraph.cs:504)

1 Like

I seem to be getting the same errors when periodically calling ‘UpdateGraphs’ whenever a NPC has changed coordinates. For the moment no other graph operations are done, this is the method called for each NPC.

public void Scan()
{
    GraphUpdateObject guo = new(scanBounds);
    guo.nnConstraint.graphMask = 1 << (int)graph.graphIndex;
    AstarPath.active.UpdateGraphs(guo);
    scanScheduled = false;
}

I’m currently using Version 5.0.6 with the following RecastGraph settings:

Relevant error logs:

AssertionException: Assertion failure. Values are equal.
Expected: -2 != -2
  at UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) [0x00043] in <2a3b1fc140ae44e9a4476e34a2a29726>:0 
  at UnityEngine.Assertions.Assert.AreNotEqual[T] (T expected, T actual, System.String message, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0005c] in <2a3b1fc140ae44e9a4476e34a2a29726>:0 
  at UnityEngine.Assertions.Assert.AreNotEqual[T] (T expected, T actual, System.String message) [0x00009] in <2a3b1fc140ae44e9a4476e34a2a29726>:0 
  at UnityEngine.Assertions.Assert.AreNotEqual (System.Int32 expected, System.Int32 actual) [0x00009] in <2a3b1fc140ae44e9a4476e34a2a29726>:0 
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.FindHierarchicalNodeChildren (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.GraphNode startNode) [0x00105] in C:\User\Unity\Project\Packages\com.arongranberg.astar\Core\Pathfinding\HierarchicalGraph.cs:451 
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x0011f] in C:\User\Unity\Project\Packages\com.arongranberg.astar\Core\Pathfinding\HierarchicalGraph.cs:538 
  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 <2a3b1fc140ae44e9a4476e34a2a29726>: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)

(Filename: Packages/com.arongranberg.astar/Core/Pathfinding/HierarchicalGraph.cs Line: 451)

NullReferenceException: Object reference not set to an instance of an object
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x0002e] in C:\User\Unity\Project\Packages\com.arongranberg.astar\Core\Pathfinding\HierarchicalGraph.cs:504 
  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 <2a3b1fc140ae44e9a4476e34a2a29726>: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)

(Filename: Packages/com.arongranberg.astar/Core/Pathfinding/HierarchicalGraph.cs Line: 504)

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) [0x000cf] in C:\User\Unity\Project\Packages\com.arongranberg.astar\Core\Misc\NavmeshEdges.cs:234 
  at Pathfinding.NavmeshEdges+JobCalculateObstacles.Execute (System.Int32 startIndex, System.Int32 count) [0x00090] in C:\User\Unity\Project\Packages\com.arongranberg.astar\Core\Misc\NavmeshEdges.cs:157 
  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) [0x0001f] in C:\User\Unity\Project\PackageCache\com.unity.collections@1.5.1\Unity.Collections\Jobs\IJobParallelForBatch.cs:44 
  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)

(Filename: Packages/com.arongranberg.astar/Core/Misc/NavmeshEdges.cs Line: 234)