GetReachableNodes NullReferenceException - dfsStack.Push(node)



I have been using this project for about a week now and have been having good results so far! Thank you so much for making this available, I will be upgrading to premium soon if my tests pan out.

I just ran into a crash though and I don’t think it’s down to user error (as far as I can tell).


NullReferenceException: Object reference not set to an instance of an object
Pathfinding.PathUtilities+c__AnonStorey0.<>m__1 (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Utilities/PathUtilities.cs:127)
Pathfinding.PathUtilities.GetReachableNodes (Pathfinding.GraphNode seed, Int32 tagMask) (at Assets/AstarPathfindingProject/Utilities/PathUtilities.cs:132)
Pathfinding.PathUtilities.IsPathPossible (System.Collections.Generic.List`1 nodes, Int32 tagMask) (at Assets/AstarPathfindingProject/Utilities/PathUtilities.cs:71)

The offending line of code is:


I am using the free package from your site:

I haven’t managed to reproduce it yet. I just added the call to IsPathPossible (List nodes, int tagMask) today and had just increased the frequency with which it gets called when I experienced the crash.

I’m assuming the problem is actually int he line that claims the dfsStack, but I’m not sure how this could fail.

Hopefully that’s enough to get you on the right track.




Thanks for reporting this!
I think there is actually a case where this might happen. It doesn’t look that way when looking at the code, and that usually means that multithreading is the cause. Some internal parts of the pathfinding system happen to call StackPool.Claim from a separate thread. If this happens at the same time as the GetReachableNodes method calls StackPool.Claim from the Unity thread, strange things might happen. In this case it seems null was returned instead.

Try to replace the StackPool.cs script with this: and see if you are still able to replicate the error.


You probably know this by now, but I made the change you suggested and it sorted the issue. Thanks and sorry for not replying sooner.


I will include the fix in the next release.