Commit 70a098b
Mark Kilfoil
Fix VesselDistanceComparer throwing ArgumentException when vessel position is NaN
Array.Sort() requires a consistent IComparer. The original implementation
casts float subtraction to int: (int)(distA - distB). This produces
inconsistent results when any vessel's transform position contains NaN
(NaN - NaN = NaN; (int)NaN = 0 regardless of operand order), which
violates the sort contract and causes an ArgumentException from Array.Sort()
on every FixedUpdate.
Also fixes a secondary issue where very large squared distances (> int.MaxValue)
could overflow and produce incorrect ordering.
Fix: replace (int)(distA - distB) with distA.CompareTo(distB), which handles
NaN and large values correctly.1 parent 109f31c commit 70a098b
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| |||
0 commit comments