Linedefs Mode, Sectors Mode, Things Mode: fixed a problem where multi-selecting many spread out map elements could result in an exception. Fixes #1053

This commit is contained in:
biwa 2024-05-11 14:28:52 +02:00
parent d0176253b0
commit 2a404cf1fc
3 changed files with 15 additions and 3 deletions

View file

@ -362,7 +362,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
if(curdistance < closest2) closest2 = curdistance;
// Return closer one
return (int)(closest1 - closest2);
// biwa: the difference between closest1 and closest2 can exceed the capacity of int, and that
// sometimes seem to cause problems, resulting in the sorting to throw an ArgumentException
// because of inconsistent results. Making sure to only return -1, 0, or 1 seems to fix the issue
// See https://github.com/UltimateDoomBuilder/UltimateDoomBuilder/issues/1053
return (closest1 - closest2) < 0 ? -1 : ((closest1 - closest2) > 0 ? 1 : 0);
});
return result;

View file

@ -722,7 +722,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// Return closer one
return (int)(closest1 - closest2);
// biwa: the difference between closest1 and closest2 can exceed the capacity of int, and that
// sometimes seem to cause problems, resulting in the sorting to throw an ArgumentException
// because of inconsistent results. Making sure to only return -1, 0, or 1 seems to fix the issue
// See https://github.com/UltimateDoomBuilder/UltimateDoomBuilder/issues/1053
return (closest1 - closest2) < 0 ? -1 : ((closest1 - closest2) > 0 ? 1 : 0);
});
return result;

View file

@ -1011,7 +1011,11 @@ namespace CodeImp.DoomBuilder.BuilderModes
double closest2 = Vector2D.DistanceSq(t2.Position, targetpoint);
// Return closer one
return (int)(closest1 - closest2);
// biwa: the difference between closest1 and closest2 can exceed the capacity of int, and that
// sometimes seem to cause problems, resulting in the sorting to throw an ArgumentException
// because of inconsistent results. Making sure to only return -1, 0, or 1 seems to fix the issue
// See https://github.com/UltimateDoomBuilder/UltimateDoomBuilder/issues/1053
return (closest1 - closest2) < 0 ? -1 : ((closest1 - closest2) > 0 ? 1 : 0);
});
return result;