[Bug] "Comparison function is incorrect" error in NavmeshCutJobs.AngleComparator with Collections package version 2.3.0-pre.3

I am using version 4.3.73 in a project with the Entities package. We decided to update the package from 1.0 to 1.1 and this new version has a dependency of the Collections package at version 2.3.0-pre.3.

At first all seemed fine, but upon testing the game and placing walls and other structures which use a NavmeshCut, an error started appearing :

InvalidOperationException: System.InvalidOperationException: Comparison function is incorrect. Compare(a, a) must return 0/equal.
This Exception was thrown from a function compiled with Burst, which has limited exception support.
0x00007ffd157f1734 (c248bd4aba5d5a64d13b20cb06d2e7d) burst_Abort_Trampoline
0x00007ffd157e2d1a (c248bd4aba5d5a64d13b20cb06d2e7d) Unity.Collections.NativeSortExtension.CheckComparer<Unity.Mathematics.float2,Pathfinding.NavmeshCutJobs.AngleComparator> (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.unity.collections@2.3.0-pre.3/Unity.Collections/NativeSort.cs:943)
0x00007ffd157e3363 (c248bd4aba5d5a64d13b20cb06d2e7d) Unity.Collections.NativeSortExtension.IntroSort<Unity.Mathematics.float2,Pathfinding.NavmeshCutJobs.AngleComparator> (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.unity.collections@2.3.0-pre.3/Unity.Collections/NativeSort.cs:582)
0x00007ffd157e3823 (c248bd4aba5d5a64d13b20cb06d2e7d) Unity.Collections.NativeSortExtension.Sort<Unity.Mathematics.float2,Pathfinding.NavmeshCutJobs.AngleComparator> (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.unity.collections@2.3.0-pre.3/Unity.Collections/NativeSort.cs:64)
0x00007ffd157e033b (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.ConvexHull (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:1003)
0x00007ffd157df5d9 (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.BoxConvexHullXZ (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:956)
0x00007ffd157dda20 (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.JobCalculateContour.Execute (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:791)
0x00007ffd157df669 (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.CalculateContour$BurstManaged (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:652)
0x00007ffd157dc9e9 (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.Pathfinding.CalculateContour_0000099A$BurstDirectCall.Invoke (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/unknown/unknown:0)
0x00007ffd157e4f09 (c248bd4aba5d5a64d13b20cb06d2e7d) Pathfinding.NavmeshCutJobs.CalculateContour(Pathfinding.NavmeshCutJobs.JobCalculateContour* job) -> void_3840ab88188035a78fc8f547af02df56 from AstarPathfindingProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (at ./Library/PackageCache/com.unity.burst@1.8.12/.Runtime/Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:652)
0x00007ffd157dc814 (c248bd4aba5d5a64d13b20cb06d2e7d) d8a1e916ec652f17071dc9ba26c01ac2
0x0000028eb8f1400a (Mono JIT Code) (wrapper managed-to-native) object:wrapper_native_0000028B50038B00 (Pathfinding.NavmeshCutJobs/JobCalculateContour*)
0x0000028eb8f145cb (Mono JIT Code) Pathfinding.NavmeshCut:GetContourBurst (Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Mathematics.float2>*,Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Pathfinding.NavmeshCut/ContourBurst>*,UnityEngine.Matrix4x4,single) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:536)
0x0000028ef4492a7b (Mono JIT Code) Pathfinding.NavmeshCut:DrawGizmos () (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:560)
0x0000028ef4467c6e (Mono JIT Code) Pathfinding.Drawing.DrawingManager:DrawGizmos (bool) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:592)
0x0000028eef2d0e33 (Mono JIT Code) Pathfinding.Drawing.DrawingManager:Submit (UnityEngine.Camera,UnityEngine.Rendering.CommandBuffer,bool,bool) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:647)
0x0000028eef2d0d13 (Mono JIT Code) Pathfinding.Drawing.DrawingManager:SubmitFrame (UnityEngine.Camera,UnityEngine.Rendering.CommandBuffer,bool) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:465)
0x0000028eef2d0a3b (Mono JIT Code) Pathfinding.Drawing.AlineHDRPCustomPass:Execute (UnityEngine.Rendering.HighDefinition.CustomPassContext) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/AlineHDRPCustomPass.cs:17)
0x0000028eef2ce4f1 (Mono JIT Code) UnityEngine.Rendering.HighDefinition.CustomPass/<>c:<ExecuteInternal>b__36_0 (UnityEngine.Rendering.HighDefinition.CustomPass/ExecutePassData,UnityEngine.Experimental.Rendering.RenderGraphModule.RenderGraphContext) (at ./Library/PackageCache/com.unity.render-pipelines.high-definition@14.0.8/Runtime/Ren
Pathfinding.NavmeshCut.GetContourBurst (Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Unity.Mathematics.float2]* outputVertices, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Pathfinding.NavmeshCut+ContourBurst]* outputContours, UnityEngine.Matrix4x4 matrix, System.Single radiusMargin) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:536)
Pathfinding.NavmeshCut.DrawGizmos () (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Navmesh/NavmeshCut.cs:557)
Pathfinding.Drawing.DrawingManager.DrawGizmos (System.Boolean usingRenderPipeline) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:591)
UnityEngine.Debug:LogException(Exception, Object)
Pathfinding.Drawing.DrawingManager:DrawGizmos(Boolean) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:593)
Pathfinding.Drawing.DrawingManager:Submit(Camera, CommandBuffer, Boolean, Boolean) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:641)
Pathfinding.Drawing.DrawingManager:SubmitFrame(Camera, CommandBuffer, Boolean) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/DrawingManager.cs:463)
Pathfinding.Drawing.AlineHDRPCustomPass:Execute(CustomPassContext) (at ./Library/PackageCache/com.arongranberg.astar@4.3.73/Drawing/AlineHDRPCustomPass.cs:16)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Looking at the package’s code, it looks like it’s coming from there :

/* com.arongranberg.astar@4.3.73\Navmesh */
/* Pathfinding.NavmeshCutJobs */

		struct AngleComparator : IComparer<float2> {
			public float2 origin;
			public int Compare (float2 lhs, float2 rhs) {
				// cross product of (lhs - origin) and (rhs - origin)
				var a = lhs - origin;
				var b = rhs - origin;
				var cross = a.x*b.y - a.y*b.x;

				if (cross == 0) {
					return math.lengthsq(b) < math.lengthsq(a) ? 1 : -1;
				} else {
					return cross < 0 ? 1 : -1;
				}
			}
		}

Which indeed does not return 0, ever.

Does a new version fix this ? preferably one which we can update seamlessly to from v4.3.73
If this issue is still present in more recent versions, can a fix for it be pushed ?

I can make a copy of the package in the project’s files and attempt fixing it by adding a if (lhs == rhs) return 0; but I have no idea what side effects this might or might not have and would prefer not wasting time experimenting blindly or reading the whole code surrounding this.

Side note that the stack trace shows “DrawGizmos” despite the Pathfinder script’s “Show Graphs” option being unchecked. Shouldn’t matter for ALINE commands but I also have gizmos disabled in the game view (they’re even disabled in the minimized scene view)
Is this normal ? it feels like there shouldn’t be any drawing commands issued when the show graphs option is disabled.

Hi

Yes, this has been fixed in a recent update.

Some things can be drawn even if gizmos are disabled, that’s why it shows up in the profiler.

1 Like

Oh sweet, thank you for the fast answer !
I’ve updated the package and after fixing all the code the update deprecated I can confirm the issue is fixed !
I expected to spend at least a couple days on this, so I’m very grateful this got done so fast.

Is there a standard way to mark this thread as solved ?

1 Like