Tentative fix for occasional crash <Comparison method violates its general contract>

This commit is contained in:
Blue (Lukas Rieger) 2021-06-15 00:51:35 +02:00
parent ad1ed6670c
commit 99c4c623f8
No known key found for this signature in database
GPG Key ID: 904C4995F9E1F800
2 changed files with 15 additions and 25 deletions

View File

@ -76,7 +76,14 @@ public Collection<Vector2i> getRegions() {
private static Collection<WorldRegionRenderTask> createTasks(BmMap map, Collection<Vector2i> regions, boolean force) {
List<WorldRegionRenderTask> tasks = new ArrayList<>(regions.size());
regions.forEach(region -> tasks.add(new WorldRegionRenderTask(map, region, force)));
tasks.sort(WorldRegionRenderTask::compare);
// get spawn region
World world = map.getWorld();
Vector2i spawnPoint = world.getSpawnPoint().toVector2(true);
Grid regionGrid = world.getRegionGrid();
Vector2i spawnRegion = regionGrid.getCell(spawnPoint);
tasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion));
return tasks;
}

View File

@ -31,6 +31,7 @@
import de.bluecolored.bluemap.core.world.World;
import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;
public class WorldRegionRenderTask implements RenderTask {
@ -187,30 +188,12 @@ private static int tileComparator(Vector2i v1, Vector2i v2) {
return v2.getY() - v1.getY();
}
public static int compare(WorldRegionRenderTask task1, WorldRegionRenderTask task2) {
if (task1.equals(task2)) return 0;
int comp = task1.map.getId().compareTo(task2.map.getId());
if (comp != 0) return comp;
if (task1.map == task2.map) { //should always be true
//sort based on the worlds spawn-point
World world = task1.map.getWorld();
Vector2i spawnPoint = world.getSpawnPoint().toVector2(true);
Grid regionGrid = world.getRegionGrid();
Vector2i spawnRegion = regionGrid.getCell(spawnPoint);
Vector2i task1Rel = task1.worldRegion.sub(spawnRegion);
Vector2i task2Rel = task2.worldRegion.sub(spawnRegion);
comp = tileComparator(task1Rel, task2Rel);
} else {
comp = tileComparator(task1.worldRegion, task2.worldRegion);
}
if (comp != 0) return comp;
return -Boolean.compare(task1.force, task2.force);
public static Comparator<WorldRegionRenderTask> defaultComparator(final Vector2i centerRegion) {
return (task1, task2) -> {
Vector2i task1Rel = task1.worldRegion.sub(centerRegion);
Vector2i task2Rel = task2.worldRegion.sub(centerRegion);
return tileComparator(task1Rel, task2Rel);
};
}
}