A ghost graph bug

Hi everyone,

Yesterday I was setting up Cache startup and got a null reference in:
JsonSerializer.cs AstarSerializer byte[] SerializeNodes (int index)

I only had 1 graph but it was also being sent index 1. I can’t quite figure out how I got a ghost graph or a length other than 1, but I fixed it by doing a sanity check in SerializeNodes. Since then I have not experienced any more problems and I can’t reproduce the problem.

`		public void SerializeNodes () {
			if (!settings.nodes) return;
			if (graphs == null) throw new InvalidOperationException ("Cannot serialize nodes with no serialized graphs (call SerializeGraphs first)");

			List<NavGraph> realGraphs = new List<NavGraph>(graphs.Length);

			foreach (NavGraph g in graphs) {
				if(g == null) {
					Debug.LogWarning(" We had a graph that was null :/");
					continue;
				}
				realGraphs.Add(g);
			}
			graphs = realGraphs.ToArray();
                        
                        ...
`

while this patched up the problem, it’s not really a fix. has anyone else experienced something similar, I would like to get to the root of this :slight_smile:

Hm… Weird… In the current version, you shouldn’t get null graphs… probably there is a tiny bug somewhere screwing it up. But if it is not repeatable, I can’t really do anything.
In the later dev versions I have switched to enabling null graphs since removing and adding graphs during runtime requires that they stay at the same graph index sometimes.