diff --git a/core/src/mindustry/async/PhysicsProcess.java b/core/src/mindustry/async/PhysicsProcess.java index 544166f25e..5a7468af9f 100644 --- a/core/src/mindustry/async/PhysicsProcess.java +++ b/core/src/mindustry/async/PhysicsProcess.java @@ -26,6 +26,7 @@ public class PhysicsProcess implements AsyncProcess{ private PhysicsWorld[] physics; private Seq refs = new Seq<>(false, 20, PhysicRef.class); private Seq> futures = new Seq<>(false, layers, Future.class); + private Seq pendingAdds = new Seq<>(false, 20, PhysicRef.class); private static volatile long maxPhysicsTime = 0; @@ -44,7 +45,8 @@ public class PhysicsProcess implements AsyncProcess{ PhysicRef ref = new PhysicRef(unit, body); refs.add(ref); - if(ref.lastLayer >= 0) physics[ref.lastLayer].add(body); + //defer adds until physics update is done + pendingAdds.add(ref); } @Override @@ -68,6 +70,13 @@ public class PhysicsProcess implements AsyncProcess{ PerfCounter.unitPhysicsAsync.add(maxPhysicsTime); maxPhysicsTime = 0; + //flush newly added entities + for(int i = 0; i < pendingAdds.size; i++){ + PhysicRef ref = pendingAdds.items[i]; + if(ref.lastLayer >= 0) physics[ref.lastLayer].add(ref.body); + } + pendingAdds.clear(); + //move entities for(PhysicRef ref : refs){ Physicsc entity = ref.entity; diff --git a/gradle.properties b/gradle.properties index a0930da613..e7d1456ea4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,4 +26,4 @@ org.gradle.caching=true org.gradle.internal.http.socketTimeout=100000 org.gradle.internal.http.connectionTimeout=100000 android.enableR8.fullMode=false -archash=8eb00ffff0 +archash=7445105cd2