Pathfinding.NavmeshBase.DestroyAllNodes NullReferenceException Crash on 5.1.2

Using a recast graph, reloading my level crashes unity.
Had the same issue before, when I was using NavmeshPrefabs for all chunks in the game.

Here are relevant logs:

Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at Pathfinding.NavmeshBase.DestroyAllNodes () [0x00060] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Graphs\NavmeshBase.cs:282 
  at Pathfinding.NavGraph.Pathfinding.IGraphInternals.DestroyAllNodes () [0x00000] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Graphs\NavGraph.cs:488 
  at Pathfinding.AstarData.DestroyAllNodes () [0x0002d] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Core\AstarData.cs:339 
  at AstarPath.OnDisable () [0x00038] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Core\AstarPath.cs:1365 


Uploading Crash Report
NullReferenceException: Object reference not set to an instance of an object
  at Pathfinding.NavmeshBase.DestroyAllNodes () [0x00060] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Graphs\NavmeshBase.cs:282 
  at Pathfinding.NavGraph.Pathfinding.IGraphInternals.DestroyAllNodes () [0x00000] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Graphs\NavGraph.cs:488 
  at Pathfinding.AstarData.DestroyAllNodes () [0x0002d] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Core\AstarData.cs:339 
  at AstarPath.OnDisable () [0x00038] in C:\Development\skopje\Assets\Addons\com.arongranberg.astar@5.1.1\Core\AstarPath.cs:1365 

(Filename: Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavmeshBase.cs Line: 282)

Header have invalid padding count. Header is corrupted!
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs:89)
Unity.Collections.Memory/Unmanaged:Free (void*,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs:27)
Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:1105)
Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:1129)
Unity.Collections.AllocatorManager/AllocatorHandle:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:613)
Unity.Collections.AllocatorManager:FreeBlock<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:143)
Unity.Collections.AllocatorManager:Free<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,void*,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:156)
Unity.Collections.AllocatorManager:Free<Unity.Collections.AllocatorManager/AllocatorHandle, Pathfinding.Int3> (Unity.Collections.AllocatorManager/AllocatorHandle&,Pathfinding.Int3*,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:161)
Unity.Collections.AllocatorManager:Free<Pathfinding.Int3> (Unity.Collections.AllocatorManager/AllocatorHandle,Pathfinding.Int3*,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:225)
Pathfinding.Util.UnsafeSpan`1<Pathfinding.Int3>:Free (Unity.Collections.Allocator) (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/Collections/Span.cs:190)
Pathfinding.Graphs.Navmesh.NavmeshTile:Dispose () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/Navmesh/NavmeshTile.cs:101)
Pathfinding.NavmeshBase:DestroyAllNodes () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavmeshBase.cs:282)
Pathfinding.NavGraph:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavGraph.cs:362)
Pathfinding.NavmeshBase:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavmeshBase.cs:264)
Pathfinding.NavGraph:Pathfinding.IGraphInternals.OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavGraph.cs:486)
Pathfinding.AstarData:ClearGraphsInternal () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarData.cs:313)
Pathfinding.AstarData:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarData.cs:346)
AstarPath:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarPath.cs:1396)

[./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs line 89]

Invalid memory pointer was detected!
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs:89)
Unity.Collections.Memory/Unmanaged:Free (void*,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs:27)
Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:1105)
Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:1129)
Unity.Collections.AllocatorManager/AllocatorHandle:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:613)
Unity.Collections.AllocatorManager:FreeBlock<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:143)
Unity.Collections.AllocatorManager:Free<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,void*,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:156)
Unity.Collections.AllocatorManager:Free<Unity.Collections.AllocatorManager/AllocatorHandle, Pathfinding.Int3> (Unity.Collections.AllocatorManager/AllocatorHandle&,Pathfinding.Int3*,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:161)
Unity.Collections.AllocatorManager:Free<Pathfinding.Int3> (Unity.Collections.AllocatorManager/AllocatorHandle,Pathfinding.Int3*,int) (at ./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/AllocatorManager.cs:225)
Pathfinding.Util.UnsafeSpan`1<Pathfinding.Int3>:Free (Unity.Collections.Allocator) (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/Collections/Span.cs:190)
Pathfinding.Graphs.Navmesh.NavmeshTile:Dispose () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/Navmesh/NavmeshTile.cs:101)
Pathfinding.NavmeshBase:DestroyAllNodes () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavmeshBase.cs:282)
Pathfinding.NavGraph:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavGraph.cs:362)
Pathfinding.NavmeshBase:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavmeshBase.cs:264)
Pathfinding.NavGraph:Pathfinding.IGraphInternals.OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Graphs/NavGraph.cs:486)
Pathfinding.AstarData:ClearGraphsInternal () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarData.cs:313)
Pathfinding.AstarData:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarData.cs:346)
AstarPath:OnDestroy () (at Assets/Addons/com.arongranberg.astar@5.1.1/Core/AstarPath.cs:1396)

[./Library/PackageCache/com.unity.collections@2.4.1/Unity.Collections/Memory.cs line 89]

Hi

Do you happen to have the contents of the line that is throwing the exception? Line numbers differ in every version, and can even differ depending on where you got the package from.

if (tiles != null) {
    for (int i = 0; i < tiles.Length; i++) {
        tiles[i].Dispose();   <= Line 282 in NavmeshBase
    }
    tiles = null;
}
public void Dispose () {
      unsafe {
          bbTree.Dispose();
          vertsInGraphSpace.Free(Allocator.Persistent);
          verts.Free(Allocator.Persistent);   <- Line 101 in NavmeshTile
          tris.Free(Allocator.Persistent);
      }
  }
}

Note: In both of the cases, I believe the scenes that the NavmeshPrefab / AStar belonged to were being unloaded. This issue even crashed unity when stopping the game.

Thanks! I’ll include a fix in the next release.