From 2e5d7a734f4324fb01a6de2263eac8c010226289 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Thu, 25 Mar 2021 15:10:40 -0700 Subject: [PATCH] Fix ConcurrentModificationException preparing frame for rendering. --- .../render/ContraptionKineticRenderer.java | 10 ++++---- .../instancing/InstancedTileRenderer.java | 24 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java index c6b3df6e6..20d0bc6a5 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionKineticRenderer.java @@ -25,7 +25,7 @@ import java.util.ArrayList; public class ContraptionKineticRenderer extends InstancedTileRenderer { - protected ArrayList actors = new ArrayList<>(); + protected ArrayList actors = new ArrayList<>(); private final WeakReference contraption; @@ -46,25 +46,25 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer actor) { + public ActorInstance createActor(Pair actor) { Template.BlockInfo blockInfo = actor.getLeft(); MovementContext context = actor.getRight(); MovementBehaviour movementBehaviour = AllMovementBehaviours.of(blockInfo.state); if (movementBehaviour != null && movementBehaviour.hasSpecialInstancedRendering()) { - com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance instance = movementBehaviour.createInstance(this, context); + ActorInstance instance = movementBehaviour.createInstance(this, context); actors.add(instance); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index ebb6f8a57..ba4592852 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -44,10 +44,7 @@ public abstract class InstancedTileRenderer

{ } public void beginFrame(double cameraX, double cameraY, double cameraZ) { - if (queuedAdditions.size() > 0) { - queuedAdditions.forEach(this::addInternal); - queuedAdditions.clear(); - } + processQueuedAdditions(); if (dynamicInstances.size() > 0) dynamicInstances.values().forEach(IDynamicInstance::beginFrame); } @@ -111,12 +108,6 @@ public abstract class InstancedTileRenderer

{ } } - public void queueAdd(T tile) { - if (!Backend.canUseInstancing()) return; - - queuedAdditions.add(tile); - } - public void update(T tile) { if (!Backend.canUseInstancing()) return; @@ -144,6 +135,19 @@ public abstract class InstancedTileRenderer

{ } } + public synchronized void queueAdd(T tile) { + if (!Backend.canUseInstancing()) return; + + queuedAdditions.add(tile); + } + + protected synchronized void processQueuedAdditions() { + if (queuedAdditions.size() > 0) { + queuedAdditions.forEach(this::addInternal); + queuedAdditions.clear(); + } + } + private void addInternal(TileEntity tile) { getInstance(tile, true); }