RuntimeError: IndexOutOfRangeException - A* 5.4.4 - When restarting multiple matches

  • A* version: 5.4.4
  • Unity version: 6000.0.58f2

Get crash when i restart a new match multiple times in a row, using:

  • Recast graph
  • Agents with Follower Entity
  • Buildings with NavMeshCut

Version 1)

I had this code first to hopefully clear the Graph & AI’s (stop Threads and such):
var data = M_Pathfinder.data;
var myGraph = data.recastGraph;
data.RemoveGraph(myGraph);

Version 2)

But with an runtime error, But now also tried:

		M_Pathfinder.data.ClearGraphs();

		PathProcessor.GraphUpdateLock l_GraphLock = AstarPath.active.PausePathfinding();

		M_Pathfinder.FlushGraphUpdates();
		M_Pathfinder.FlushWorkItems();

		l_GraphLock.Release();

M_Pathfinder is a class: AstarPath // Its just a class variable to have a easy reference to active (only one) “Pathfinder”, I assume I could as easy use “AstarPath.active”.

I got another error with my Version 1 - code, this error posted here, is with the version 2 code i have above here.

Both uses this call to load the map:

I load a Serialized graph using:
M_Pathfinder.data.DeserializeGraphs(mapData.bytes);
M_Pathfinder.navmeshUpdates.ForceUpdate();

And here is the error:

IndexOutOfRangeException: System.IndexOutOfRangeException:
This Exception was thrown from a function compiled with Burst, which has limited exception support.
0x00007fffbb5324eb (Unity) burst_abort
0x00007fffa2204ebe (946fc54953bfc531f2fbd5c3057c8f5) burst_Abort_Trampoline
0x00007fffa21806a3 (946fc54953bfc531f2fbd5c3057c8f5) Pathfinding.Path.SearchContext.OpenCandidateConnectionBurst_00000670$BurstDirectCall.Invoke (at E:/Programmering/Projekt/Unity/Myriad Mayhem/Library/PackageCache/com.unity.burst@f7a407abf4d5/.Runtime/unknown/unknown:0)
0x00007fffa21e6376 (946fc54953bfc531f2fbd5c3057c8f5) Pathfinding.TriangleMeshNode.OpenSingleEdgeBurst(ref Pathfinding.Int3 s1, ref Pathfinding.Int3 s2, ref Pathfinding.Int3 pos, ushort pathID, uint pathNodeIndex, uint candidatePathNodeIndex, uint candidateNodeIndex, uint candidateG, float traversalCostFactor, ref Pathfinding.Collections.UnsafeSpan1<Pathfinding.PathNode> pathNodes, ref Pathfinding.BinaryHeap heap, ref Pathfinding.HeuristicObjective heuristicObjective) -> void_64e83775f2be36af61b6ae2b25463387 from AstarPathfindingProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at E:/Programmering/Projekt/Unity/Myriad Mayhem/Library/PackageCache/com.unity.burst@f7a407abf4d5/.Runtime/unknown/unknown:0) 0x00007fffa21e5fc9 (946fc54953bfc531f2fbd5c3057c8f5) 967b7a9aa4550fb91c8a25b2ad70d8d3 0x0000027b83938995 (Mono JIT Code) (wrapper managed-to-native) Pathfinding.TriangleMeshNode/Pathfinding.OpenSingleEdgeBurst_000008D2$BurstDirectCall:wrapper_native_indirect_0000027F23997EB8 (intptr&,Pathfinding.Int3&,Pathfinding.Int3&,Pathfinding.Int3&,uint16,uint,uint,uint,uint,single,Pathfinding.Collections.UnsafeSpan1<Pathfinding.PathNode>&,Pathfinding.BinaryHeap&,Pathfinding.HeuristicObjective&)
0x0000027b83938473 (Mono JIT Code) Pathfinding.TriangleMeshNode/Pathfinding.OpenSingleEdgeBurst_000008D2$BurstDirectCall:Invoke (Pathfinding.Int3&,Pathfinding.Int3&,Pathfinding.Int3&,uint16,uint,uint,uint,uint,single,Pathfinding.Collections.UnsafeSpan1<Pathfinding.PathNode>&,Pathfinding.BinaryHeap&,Pathfinding.HeuristicObjective&) 0x0000027b8393827b (Mono JIT Code) Pathfinding.TriangleMeshNode:OpenSingleEdgeBurst (Pathfinding.Int3&,Pathfinding.Int3&,Pathfinding.Int3&,uint16,uint,uint,uint,uint,single,Pathfinding.Collections.UnsafeSpan1<Pathfinding.PathNode>&,Pathfinding.BinaryHeap&,Pathfinding.HeuristicObjective&)
0x0000027b83937d2b (Mono JIT Code) Pathfinding.TriangleMeshNode:OpenSingleEdge (Pathfinding.Path/SearchContext&,uint,Pathfinding.TriangleMeshNode,int,Pathfinding.Int3,uint,single) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:488)
0x0000027b83936503 (Mono JIT Code) Pathfinding.TriangleMeshNode:OpenAtPoint (Pathfinding.Path/SearchContext&,uint,Pathfinding.Int3,int,uint) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:416)
0x0000027b83936133 (Mono JIT Code) Pathfinding.TriangleMeshNode:OpenAtPoint (Pathfinding.Path/SearchContext&,uint,Pathfinding.Int3,int,uint) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:395)
0x0000027b83939bc3 (Mono JIT Code) Pathfinding.TriangleMeshNode:Open (Pathfinding.Path/SearchContext&,uint,uint) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:352)
0x0000027b839343b4 (Mono JIT Code) Pathfinding.Path:CalculateStep (Pathfinding.Path/SearchContext&,long) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/Path.cs:1172)
0x0000027b839339d0 (Mono JIT Code) Pathfinding.Path:Pathfinding.IPathInternals.CalculateStep (Pathfinding.Path/SearchContext&,long) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/Path.cs:1199)
0x0000027b812d3d0c (Mono JIT Code) Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler,Pathfinding.Sync.BlockableChannel1/Receiver<Pathfinding.Path>) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/PathProcessor.cs:345) 0x0000027b812d2e5b (Mono JIT Code) Pathfinding.PathProcessor/<>c__DisplayClass27_0:<StartThreads>b__0 () (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/PathProcessor.cs:122) 0x0000027b80489292 (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart_Context (object) 0x0000027b804353ce (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) 0x0000027b8043495b (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) 0x0000027b804886a3 (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) 0x0000027b804882db (Mono JIT Code) System.Threading.ThreadHelper:ThreadStart () 0x0000027b7faafc98 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr) 0x00007fffa98a6e8e (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/ Pathfinding.TriangleMeshNode+OpenSingleEdgeBurst_000008D2$BurstDirectCall.Invoke (Pathfinding.Int3& s1, Pathfinding.Int3& s2, Pathfinding.Int3& pos, System.UInt16 pathID, System.UInt32 pathNodeIndex, System.UInt32 candidatePathNodeIndex, System.UInt32 candidateNodeIndex, System.UInt32 candidateG, System.Single traversalCostFactor, Pathfinding.Collections.UnsafeSpan1[Pathfinding.PathNode]& pathNodes, Pathfinding.BinaryHeap& heap, Pathfinding.HeuristicObjective& heuristicObjective) (at :0)
Pathfinding.TriangleMeshNode.OpenSingleEdgeBurst (Pathfinding.Int3& s1, Pathfinding.Int3& s2, Pathfinding.Int3& pos, System.UInt16 pathID, System.UInt32 pathNodeIndex, System.UInt32 candidatePathNodeIndex, System.UInt32 candidateNodeIndex, System.UInt32 candidateG, System.Single traversalCostFactor, Pathfinding.Collections.UnsafeSpan1[Pathfinding.PathNode]& pathNodes, Pathfinding.BinaryHeap& heap, Pathfinding.HeuristicObjective& heuristicObjective) <0x27b83938190 + 0x000ea> in <b9443d624af84be79249312bf2631832>:0 Pathfinding.TriangleMeshNode.OpenSingleEdge (Pathfinding.Path+SearchContext& ctx, System.UInt32 pathNodeIndex, Pathfinding.TriangleMeshNode other, System.Int32 sharedEdgeOnOtherNode, Pathfinding.Int3 pos, System.UInt32 gScore, System.Single traversalCostFactor) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:488) Pathfinding.TriangleMeshNode.OpenAtPoint (Pathfinding.Path+SearchContext& ctx, System.UInt32 pathNodeIndex, Pathfinding.Int3 pos, System.Int32 edge, System.UInt32 gScore) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:416) Pathfinding.TriangleMeshNode.OpenAtPoint (Pathfinding.Path+SearchContext& ctx, System.UInt32 pathNodeIndex, Pathfinding.Int3 pos, System.Int32 edge, System.UInt32 gScore) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:395) Pathfinding.TriangleMeshNode.Open (Pathfinding.Path+SearchContext& ctx, System.UInt32 pathNodeIndex, System.UInt32 gScore) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Graphs/Nodes/TriangleMeshNode.cs:352) Pathfinding.Path.CalculateStep (Pathfinding.Path+SearchContext& ctx, System.Int64 targetTick) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/Path.cs:1172) Pathfinding.Path.Pathfinding.IPathInternals.CalculateStep (Pathfinding.Path+SearchContext& ctx, System.Int64 targetTick) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/Path.cs:1199) Pathfinding.PathProcessor.CalculatePathsThreaded (Pathfinding.PathHandler pathHandler, Pathfinding.Sync.BlockableChannel1+Receiver[T] receiver) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/PathProcessor.cs:345)
UnityEngine.Debug:LogException(Exception)
Pathfinding.PathProcessor:CalculatePathsThreaded(PathHandler, Receiver) (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/PathProcessor.cs:395)
Pathfinding.<>c__DisplayClass27_0:b__0() (at ./Library/PackageCache/com.arongranberg.astar@8c655abf5bb5/Core/Pathfinding/PathProcessor.cs:122)
System.Threading.ThreadHelper:ThreadStart()

Which individual line is throwing the exception?

I would debug to make sure that myGraph isn’t null, or that AstarPath.active.data.graphs isn’t empty since this is only happening when restarting multiple matches.

Thanks for reaching out :D! Ahh sorry i was a bit vague, the error is not generated by any code i call. that error is generated by the A system when i restart a new match (sometimes) - As if it forgot to stop a thread for a unit that no longer exists.
*
The "clearing” is happening when you “end a match → Return to main menu”, but the bug appears when you have started a new match & got into the game.

I just showed what methods i use to Create Mapgraph & ClearMapGraph + Units AI (including stopping their threads), only other code i have that touches A** code is unit._pathfinderManager.SetDestination() (or what it is called again).

Edit: I also remove all units when closing game (even if i pool objects normally) - to avoid these kind of errors.

Thanks once again :).

A followup / idea - As i pause the game before i do that clearing, maybe that could be the culprit? e.g. units thread/coroutines maybe haven’t run their update-loop & know the game is paused.

So I’m gonna try to avoid pausing and and instead pause when we start a new match instead (and ofc unpause when finished loading new match).

Ahhh I see. I thought this was a result of that code, mb! Can you check the versions of your Unity dependencies like Burst, Collections, etc?

Sure, and no worries, was alot of text :slight_smile:.
Burst: 1.8.24
Collections: 2.6.2
Mathmatics 1.2.6

Those are what I can see the package is having as dependencies.

If you can I’d try updating Burst and Mathematics, in a cloned project probably, to be safe. For the safe of troubleshooting, you can also try and spin up a blank project with these dependency versions and see if you can trigger it in a project with nothing in it.