A node in a RecastGraph contained a connection to a destroyed TriangleMeshNode

  • A* version: 5.4.6
  • Unity version: 6000.3.15f1

Hi, we’re currently having an issue where, on extremely rare occasions, we get an error that results in a hard crash. We’ve only seen it in builds (Has occurred twice that I know of) and I have not found any to find any way replicating the error.

First we get:

[Exception] System.InvalidOperationException: A node in a RecastGraph contained a connection to a destroyed TriangleMeshNode.
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents+<>c.<FindHierarchicalNodeChildren>b__13_0 (Pathfinding.GraphNode neighbour, Pathfinding.HierarchicalGraph+JobRecalculateComponents+Context& context) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:410
  at UnityEngine.InputSystem.Utilities.NamedValue.set_value (UnityEngine.InputSystem.Utilities.PrimitiveValue value) [0x00000] in ./Library/PackageCache/com.unity.inputsystem@21a28c3a6c83/InputSystem/Utilities/NamedValue.cs:22
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.FindHierarchicalNodeChildren (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, Pathfinding.GraphNode startNode) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:427
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:524
  at Pathfinding.HierarchicalGraph.RecalculateIfNecessary () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:554
  at Pathfinding.WorkItemProcessor.EnsureValidFloodFill () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:315
  at Pathfinding.WorkItemProcessor.ProcessWorkItems (System.Boolean force, System.Boolean sendEvents) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:411
  at AstarPath.PerformBlockingActions (System.Boolean force) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:932
  at AstarPath.Update () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:910
  at UnityEngine.Logger.LogException (System.Exception exception, UnityEngine.Object context)
  at UnityEngine.Debug.CallOverridenDebugHandler (System.Exception exception, UnityEngine.Object obj)
  at Pathfinding.HierarchicalGraph.RecalculateIfNecessary () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:554
  at Pathfinding.WorkItemProcessor.EnsureValidFloodFill () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:315
  at Pathfinding.WorkItemProcessor.ProcessWorkItems (System.Boolean force, System.Boolean sendEvents) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:411
  at AstarPath.PerformBlockingActions (System.Boolean force) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:932
  at AstarPath.Update () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:910

Which is then followed by

[Exception] System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.RemoveHierarchicalNode (Pathfinding.HierarchicalGraph hGraph, System.Int32 hierarchicalNode, System.Boolean removeAdjacentSmallNodes) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:322
  at Pathfinding.HierarchicalGraph+JobRecalculateComponents.Execute () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:492
  at Pathfinding.HierarchicalGraph.RecalculateIfNecessary () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:554
  at Pathfinding.WorkItemProcessor.EnsureValidFloodFill () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:315
  at Pathfinding.WorkItemProcessor.ProcessWorkItems (System.Boolean force, System.Boolean sendEvents) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:411
  at AstarPath.PerformBlockingActions (System.Boolean force) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:932
  at AstarPath.Update () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:910
  at UnityEngine.Logger.LogException (System.Exception exception, UnityEngine.Object context)
  at UnityEngine.Debug.CallOverridenDebugHandler (System.Exception exception, UnityEngine.Object obj)
  at Pathfinding.HierarchicalGraph.RecalculateIfNecessary () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Pathfinding/HierarchicalGraph.cs:554
  at Pathfinding.WorkItemProcessor.EnsureValidFloodFill () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:315
  at Pathfinding.WorkItemProcessor.ProcessWorkItems (System.Boolean force, System.Boolean sendEvents) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/Misc/WorkItemProcessor.cs:411
  at AstarPath.PerformBlockingActions (System.Boolean force) [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:932
  at AstarPath.Update () [0x00000] in ./Library/PackageCache/com.arongranberg.astar@85d89969624b/Core/AstarPath.cs:910

I’ve looked through our code and can’t see anything obvious that would lead to a destroyed TriangleMeshNode, we don’t create or destroy any connections manually, but we do recalculate the graph occasionally using AStarPath.UpdateGraphs. We also have a large number of NavCuts in our scene, though we use our own NavCut scripts that overrides RequiresUpdate for performance reasons.

Any thoughts or help on this would be appreciated. I’ve seen similar errors in other posts, but can’t find any confirmed cause for this issue.

Do you think this is likely where it’s coming from? Are you able to run a version of your game where it’s just…running indefinitely in a scenario where it will crash from updating its graphs? (Does it require player input? And if so, can you rig it to automatically simulate that?)

Then if you can get it to crash you can try running it indefinitely a few times to crash, and a few times to without updating your graphs. Would help a lot on this side of the river. Let me know if that’s doable :victory_hand:

In the game, the player can build and destroy structures, which means we have to update the A* navmesh at runtime. We think the issue is happening somewhere during these graph updates, although we haven’t been able to reliably reproduce it by repeating the same actions. We may be able to write something to automate this to test, though it will likely be a few weeks before I can dig into that.

For now, we’re using a sanitiser script which seems to prevent the error spam and crash after the initial TriangleMeshNode error. It essentially just cleans up any destroyed nodes and makes any connections that had them as dirty.

I see. I think the best action for now is to keep an eye on if that sanitizer script is helping- especially if it’s able to log anything it finds that may be of help. Whatever you find from that/an automated test if you find the space to do that would be great as well! I’ll keep my ears open for it :+1: