From 5b2dc021a6e43ec06d426d32977a7298b8b2aa4e Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 18 Jul 2021 08:56:48 -0400 Subject: [PATCH] Prevent concurrent modification in BlockIndexer#eachBlock --- core/src/mindustry/ai/BlockIndexer.java | 36 +++++++++++++++++-------- gradle.properties | 2 +- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/core/src/mindustry/ai/BlockIndexer.java b/core/src/mindustry/ai/BlockIndexer.java index 272fb6d543..e23d270175 100644 --- a/core/src/mindustry/ai/BlockIndexer.java +++ b/core/src/mindustry/ai/BlockIndexer.java @@ -211,13 +211,12 @@ public class BlockIndexer{ } public boolean eachBlock(@Nullable Team team, float wx, float wy, float range, Boolf pred, Cons cons){ - returnBool = false; + breturnArray.clear(); if(team == null){ allBuildings(wx, wy, range, b -> { if(pred.get(b)){ - returnBool = true; - cons.get(b); + breturnArray.add(b); } }); }else{ @@ -225,13 +224,20 @@ public class BlockIndexer{ if(buildings == null) return false; buildings.intersect(wx - range, wy - range, range*2f, range*2f, b -> { if(b.within(wx, wy, range + b.hitSize() / 2f) && pred.get(b)){ - returnBool = true; - cons.get(b); + breturnArray.add(b); } }); } - return returnBool; + int size = breturnArray.size; + var items = breturnArray.items; + for(int i = 0; i < size; i++){ + cons.get(items[i]); + items[i] = null; + } + breturnArray.size = 0; + + return size > 0; } /** Get all enemy blocks with a flag. */ @@ -274,16 +280,24 @@ public class BlockIndexer{ } public void allBuildings(float x, float y, float range, Cons cons){ + breturnArray.clear(); for(int i = 0; i < activeTeams.size; i++){ Team team = activeTeams.items[i]; var buildings = team.data().buildings; if(buildings == null) continue; - buildings.intersect(x - range, y - range, range*2f, range*2f, b -> { - if(b.within(x, y, range + b.hitSize()/2f)){ - cons.get(b); - } - }); + buildings.intersect(x - range, y - range, range*2f, range*2f, breturnArray); } + + var items = breturnArray.items; + int size = breturnArray.size; + for(int i = 0; i < size; i++){ + var b = items[i]; + if(b.within(x, y, range + b.hitSize()/2f)){ + cons.get(b); + } + items[i] = null; + } + breturnArray.size = 0; } public Building findEnemyTile(@Nullable Team team, float x, float y, float range, Boolf pred){ diff --git a/gradle.properties b/gradle.properties index c626e234a5..97ea62c507 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ kapt.include.compile.classpath=false kotlin.stdlib.default.dependency=false #needed for android compilation android.useAndroidX=true -archash=58cab1a87e1ed024a0044c4639594dc22088c87e +archash=65939d39bd6b20ddcfa85cb76cb1ceb815d91aec