Possible issue with ClearGraphs in 4.3.39

Hi there, I’ve started re-implementing our game’s navigation using the plugin, so expect more and more questions soon :slight_smile:
I am currently using 4.3.39 to benefit from the Burst compilation.

I am generating several graphs from code. When I call AstarPath.active.data.ClearGraphs() to make sure there are not graphs in the scene, and then try to add a new graph using AstarPath.active.data.AddGraph(typeof(GridGraph)) as GridGraph;, I am getting a null reference exception. This is due to line 346 in AstarData.cs:

		void ClearGraphsInternal () {
			if (graphs == null) return;
			for (int i = 0; i < graphs.Length; i++) {
				if (graphs[i] != null) {
					((IGraphInternals)graphs[i]).OnDestroy();
					graphs[i].active = null;
				}
			}
			**graphs = null;**
			UpdateShortcuts();
		}

(in bold above).
I think the line should be changed to graphs = new NavGraph[0]; to match the initialization, no?

Good catch! I’ll fix this in the next version.

1 Like