Unhandled Exception issue

I got these three exceptions in a row:

IndexOutOfRangeException: Array index is out of range.
at Pathfinding.GridGraph.GetNearestForce (Vector3 position, Pathfinding.NNConstraint constraint) [0x005f5] in \Assets\AstarPathfindingProject\Generators\GridGenerator.cs:775
at AstarPath.GetNearest (Vector3 position, Pathfinding.NNConstraint constraint, Pathfinding.GraphNode hint) [0x0017d] in \Assets\AstarPathfindingProject\Core\AstarPath.cs:2846
at Pathfinding.ABPath.Prepare () [0x0009e] in \Assets\AstarPathfindingProject\Pathfinders\ABPath.cs:195
at AstarPath.CalculatePathsThreaded (System.Object _threadInfo) [0x000d2] in \Assets\AstarPathfindingProject\Core\AstarPath.cs:2462
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
AstarPath:CalculatePathsThreaded(Object) (at \Assets\AstarPathfindingProject\Core\AstarPath.cs:2558)

Then

Unhandled exception during pathfinding. Terminating.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
AstarPath:CalculatePathsThreaded(Object) (at \Assets\AstarPathfindingProject\Core\AstarPath.cs:2559)

And then

Error : This part should never be reached.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
AstarPath:CalculatePathsThreaded(Object) (at \Assets\AstarPathfindingProject\Core\AstarPath.cs:2565)

It seems to be caused by changing bounds / loading / reloading graphs while it’s still searching. It causes everything to stop working. How do I work around this and make sure it doesn’t happen, or at least turn itself back on after this crash?

Hi

How exactly are you modifying the graph?

At this part I think I removed all the graphs and loaded new graphs (it was between stages)

If you just called DeserializeGraphs(bytes) it should ensure that the pathfinding threads are paused. Are you calling anything else?

foreach (var grid in _astarGrids)
{
AstarPath.active.astarData.RemoveGraph(grid.Value);
}

I have to remove the old graphs first.

Hm… At least in my dev version the RemoveGraph method ensures that the pathfinding threads are stopped. What version are you using?

3.8.1 is the last version in the changelog file.
I should upgrade, shouldn’t I?

Hi

From what I can see, 3.8.1 should also make sure the pathfinding threads are stopped. It might have been caused by an unrelated bug though, so upgrading might be a good idea.

I’ll try and let you know if it helped

Ok now i’m having a completely different issue. Tried baking my graphs by exporting like I always do.
So I used this:

    foreach (var graph in AstarPath.active.astarData.graphs)
    {
        if (graph != null)
        {
            AstarPath.active.astarData.RemoveGraph(graph);
        }
    }

to remove the graphs after I baked the first batch but then when I create a graph it throws this error:

NullReferenceException: Object reference not set to an instance of an object
Pathfinding.GridNode.FloodFill (System.Collections.Generic.Stack`1 stack, UInt32 region) (at Assets/AstarPathfindingProject/Generators/NodeClasses/GridNode.cs:235)
AstarPath+c__AnonStorey3.<>m__0 (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1902)
Pathfinding.GridGraph.GetNodes (Pathfinding.GraphNodeDelegateCancelable del) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:106)
AstarPath.FloodFill () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1912)
AstarPath.ScanLoop (Pathfinding.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2134)
AstarPath.Scan () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:2017)

Edit: I found you little bug and fixed it. As you can see in AstarData.cs:500 -

        bool foundEmpty = false;
  	for (int i = 0; i < graphs.Length; i++) {
  		if (graphs[i] == null) {
  			graphs[i] = graph;
  			graph.graphIndex = (uint)i;
  			foundEmpty = true;
  		    break;    // This break is missing in the original code. I added it
  		}
  	}

Without the added break, it will just replace all nulls (as many as the number of graphs removed beforehand) with the current one. Please fix it :slight_smile:

Also, it seems like the threading bug still happens:

IndexOutOfRangeException: Array index is out of range.
at Pathfinding.GridGraph.GetNearestForce (Vector3 position, Pathfinding.NNConstraint constraint) [0x00614] in Assets\AstarPathfindingProject\Generators\GridGenerator.cs:778
at AstarPath.GetNearest (Vector3 position, Pathfinding.NNConstraint constraint, Pathfinding.GraphNode hint) [0x0017d] in Assets\AstarPathfindingProject\Core\AstarPath.cs:2893
at Pathfinding.ABPath.Prepare () [0x0009e] in Assets\AstarPathfindingProject\Pathfinders\ABPath.cs:195
at AstarPath.CalculatePathsThreaded (System.Object _threadInfo) [0x000d2] in Assets\AstarPathfindingProject\Core\AstarPath.cs:2501
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
AstarPath:CalculatePathsThreaded(Object) (at Assets\AstarPathfindingProject\Core\AstarPath.cs:2597)

(Filename: Assets/AstarPathfindingProject/Generators/GridGenerator.cs Line: 778)

Then

Unhandled exception during pathfinding. Terminating.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
AstarPath:CalculatePathsThreaded(Object) (at \Assets\AstarPathfindingProject\Core\AstarPath.cs:2598)

And then

Error : This part should never be reached.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogError(Object)
AstarPath:CalculatePathsThreaded(Object) (at \Assets\AstarPathfindingProject\Core\AstarPath.cs:2604)

Also, after upgrading i’m starting to get lots of these:

Guid Conflict when importing graphs additively. Imported graph will get a new Guid.
This message is (relatively) harmless.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:LogWarning(Object)
Pathfinding.AstarData:DeserializeGraphsPartAdditive(AstarSerializer) (at Assets\AstarPathfindingProject\Core\AstarData.cs:352)
Pathfinding.AstarData:DeserializeGraphsAdditive(Byte[]) (at Assets\AstarPathfindingProject\Core\AstarData.cs:292)
Pathfinding.AstarData:DeserializeGraphs(Byte[]) (at Assets\AstarPathfindingProject\Core\AstarData.cs:277)
GraphBake:ImportGraphs(String) (at Assets\Scripts\AI\Baking\GraphBake.cs:372)
InfluenceMapManager:LoadBakedGraphs(String, Single, String) (at Assets\Scripts\AI\Influence Maps\InfluenceMapManager.cs:152)
InfluenceMapManager:OnPostSegmentSpawnServer() (at Assets\Scripts\AI\Influence Maps\InfluenceMapManager.cs:129)
ActionExtensions:SafeInvoke(Action) (at Assets\Scripts\Utils\ActionExtensions.cs:11)
Assets.Scripts.Managers.GameFlowManager:OnCompletedLoadingSegmentServer() (at Assets\Scripts\Managers\GameFlowManager.cs:655)
ActionExtensions:SafeInvoke(Action) (at Assets\Scripts\Utils\ActionExtensions.cs:11)
Assets.Scripts.Managers.c__Iterator2:MoveNext() (at Assets\Scripts\Managers\SegmentManager.cs:369)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr) (at C:\buildslave\unity\build\Runtime\Export\Coroutines.cs:17)

(Filename: Assets/AstarPathfindingProject/Core/AstarData.cs Line: 352)

Hey, still waiting for an answer here :slight_smile:

Hi

Sorry about that.
Would it be possible for you to share an example project so that I can replicate this bug?

Ok we’re dealing with 3 bugs here.

  1. I fixed this one for you - you can see it above. Should add it to the version.
  2. The IndexOutOfRange - the problem with this one is that it crashes the whole pathfinding system and it only happens after about a day or two, probably because of a race condition with the threads.
  3. The wrong guid warning - This just happens when exporting and importing graphs

That has already been fixed, but the fix has not been released yet. It was first reported here: Missing break in AstarData.AddGraph()

It just logs that warning because you seem to be additively importing the “same” graph (as in that is based on the same original graph. Each graph get a unique ID when they are created, if you save one instance of that graph to a file and then load it additively twice then you would end up with two graphs with the same unique ID, which we obviously cannot have, so it generates a new ID). You do not need to worry about this.

Ah. Annoying that it happens after so long… Are you perhaps changing the width or depth of the grid graph during runtime?

Also. I could send you the latest development version so you could test that. If we are lucky it has already been fixed (as I have refactored a few things related to multithreading).

…though looking at the stack trace for (3) you do not seem to be loading graphs additively. It must have saved multiple graphs with the same GUID somehow. I’m not sure how that could happen. Do you think you could send me the graph data file that you are trying to load?

But I don’t do that. What I do is create several graphs offline and save them all as one export file. Than I just import that file once in the game. I do import it again but only after I cleared and removed all the graphs. The issue is that I didn’t receive that warning before updating from 3.8.1.

I don’t think so. It happens always after I remove all the graphs, before loading new ones. Sending a version is problematic. But i’ll try to put up a server for the weekend and test if I can reproduce it.

Yes, sure. How do I send it? It won’t allow me to upload this type here.

I have sent you a PM

Um… All your GUIDs are zero…

Do you think you could send me the contents of the GridNodeBase.SerializeReferences and GridNodeBase.DeserializeReferences methods? You are using the 3.8.3 beta version but I only seem to have a version control tag for 3.8.2 and 3.8.4 and I think some things might have changed in those methods between those versions.

I’m pretty sure i’m using 3.8.6 - That’s what the changelog says.