Crash when stoping game

I am getting weird issues with the tool. For example when I stop the game in the editor I get

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.AstarData.AddGraph (System.Type type) (at Assets/AstarPathfindingProject/Core/AstarData.cs:478)
Pathfinding.NodeLink2.InternalOnPostScan () (at Assets/AstarPathfindingProject/Core/Misc/NodeLink2.cs:83)
Pathfinding.NodeLink2.OnPostScan () (at Assets/AstarPathfindingProject/Core/Misc/NodeLink2.cs:73)
Pathfinding.NodeLink2.OnGraphsPostUpdate () (at Assets/AstarPathfindingProject/Core/Misc/NodeLink2.cs:123)
Pathfinding.GraphModifier.TriggerEvent (EventType type) (at Assets/AstarPathfindingProject/Core/Misc/GraphModifier.cs:79)
AstarPath.ProcessGraphUpdates (Boolean force) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1361)
AstarPath.ProcessWorkItems (Boolean force) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1041)

Also I have some GraphUpdateScene objects to modify the tags and they dont seem to be working when I call

AstarPath.active.ScanLoop( progress => {
Debug.Log( "Scanning… " + progress.description + " - " + (progress.progress*100).ToString( “0” ) + “%” );
} );

They dont seem to be doing anything.

Also when I scan to test in the editor I am getting:

There was an error generating the graphs:
System.Exception: Trying to initialize a node when it is not safe to initialize any nodes. Must be done during a graph update
at AstarPath.InitializeNode (Pathfinding.GraphNode node) [0x00010] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\AstarPath.cs:1951
at Pathfinding.GraphNode…ctor (.AstarPath astar) [0x0001e] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\Nodes\GraphNode.cs:34
at Pathfinding.PointNode…ctor (.AstarPath astar) [0x00000] in :0
at Pathfinding.PointGraph.AddNode (Int3 position) [0x00000] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Generators\PointGenerator.cs:355
at Pathfinding.NodeLink2.InternalOnPostScan () [0x00099] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\Misc\NodeLink2.cs:91
at Pathfinding.NodeLink2.OnPostScan () [0x00000] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\Misc\NodeLink2.cs:73
at Pathfinding.GraphModifier.TriggerEvent (EventType type) [0x0007c] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\Misc\GraphModifier.cs:70
at AstarPath.ScanLoop (Pathfinding.OnScanStatus statusCallback) [0x00457] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Core\AstarPath.cs:2125
at AstarPathEditor.MenuScan () [0x000c1] in D:\Documents\projects\ThiefAcademy\vrkit\Assets\AstarPathfindingProject\Editor\AstarPathEditor.cs:1692

If you think this is a bug, please contact me on arongranberg.com (post a comment)

UnityEngine.Debug:LogError(Object)
AstarPathEditor:MenuScan() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:1694)
AstarPathEditor:OnInspectorGUI() (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:308)
UnityEditor.DockArea:OnGUI()

I dont understand what is going on it seems everything was fine.

1 Like

I was able to understand that in fact the Graph update scene objects were changing the tags but because they only changed a small portion I wasnt seeing the color difference.Nevertheless, all those other bugs are just not reasonable . I do have a recurring problem where the RichFunnel causes a stack overflow:

StackOverflowException: The requested operation caused a stack overflow.
Pathfinding.RichFunnel.SimplifyPath3 (IRaycastableGraph rcg, System.Collections.Generic.List1 nodes, Int32 start, Int32 end, System.Collections.Generic.List1 result, Vector3 startPoint, Vector3 endPoint, Int32 depth) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:286)
Pathfinding.RichFunnel.SimplifyPath3 (IRaycastableGraph rcg, System.Collections.Generic.List1 nodes, Int32 start, Int32 end, System.Collections.Generic.List1 result, Vector3 startPoint, Vector3 endPoint, Int32 depth) (at Assets/AstarPathfindingProject/Core/AI/RichPath.cs:286)
…

Hi

Something looks very broken there. I haven’t seen that before. Is that the full stack trace for the first exception?

As for the RichAI. That is a bug I have been trying to track down for a while, but it has been proving hard to reproduce for me. It comes from the path simplification algorithm (see the simplification mode setting in the inspector). In any case I think I am going to remove all modes except the Iterative mode since that works best in almost all situations, the iterative mode also does not have that bug as far as I am aware. So try switching to the iterative mode.

Which version of the package are you using?

Hey thanks for the response.

I am using version 3.8.8.1 ( downloaded not from the asset store but your site).
As for the stack overflow I thought I had tried all different simplifications but I will switch to the iterative one then.

Yep that was the whole stack trace for the first exception.
I was able to remove some of the problems by for example, removing the AStarPath component from the scene and adding it again. Something must have been wrong in the serialization. ( I saw that a new PointGraph was being added dynamicly and it stays after the application closes). I am using Nodelink2 in the scene.

I added the TileHandlerHelper dynamicly instead of having it in the scene from the beginning ( instantiating after the scan). As it was complaining the recastGraph was null.

AstarPath.active.astarData.UpdateShortcuts();
_tileHandlerHelper = gameObject.AddComponent< TileHandlerHelper >();
_tileHandlerHelper.updateInterval = 0.1f;

Another thing that I am doing that i think it isnt normal is:before the scan I call snapBoundsToScene ( I have a procedurally generated levels so this is important)

foreach ( NavGraph graph in AstarPath.active.graphs ) {
RecastGraph navGraph = graph as RecastGraph;
if ( navGraph != null ) {
navGraph.SnapForceBoundsToScene();
}
}

I am using AstarPath.OnLatePostScan to initialize everything after the scan

AstarPath.active.ScanLoop( progress => {
Debug.Log( "Scanning… " + progress.description + " - " + (progress.progress*100).ToString( “0” ) + “%” );
} );

Are you sure? Because this method “AstarPath.ProcessWorkItems (Boolean force) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1041)” is not anything called by Unity, so it must have been called by some other method. Maybe the log just showed a limited number of entries in the stack trace.

If you have a backup of the project when it threw all those exceptions I would be very interested in having a look at it because it should never throw exceptions like that.

I dont have it. I needed a solution urgently and despite having a hard time I tried to look into a solution myself and ended up solving it without really understanding whats was going on. I suspect something to do with unity’s prefabs as I have my Astar as a prefab and I see that sometimes it adds graphs without reason to the prefab and other weird stuff. have a look into it.

Odd. I will try to replicate the issue even though I don’t have that much to go on.