Fix ConcurrentModificationException preparing frame for rendering.

This commit is contained in:
JozsefA 2021-03-25 15:10:40 -07:00
parent affb8abfbd
commit 2e5d7a734f
2 changed files with 19 additions and 15 deletions

View File

@ -25,7 +25,7 @@ import java.util.ArrayList;
public class ContraptionKineticRenderer extends InstancedTileRenderer<ContraptionProgram> {
protected ArrayList<com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance> actors = new ArrayList<>();
protected ArrayList<ActorInstance> actors = new ArrayList<>();
private final WeakReference<RenderedContraption> contraption;
@ -46,25 +46,25 @@ public class ContraptionKineticRenderer extends InstancedTileRenderer<Contraptio
@Override
public void tick() {
actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::tick);
actors.forEach(ActorInstance::tick);
}
@Override
public void beginFrame(double cameraX, double cameraY, double cameraZ) {
super.beginFrame(cameraX, cameraY, cameraZ);
actors.forEach(com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance::beginFrame);
actors.forEach(ActorInstance::beginFrame);
}
@Nullable
public com.simibubi.create.content.contraptions.components.structureMovement.render.ActorInstance createActor(Pair<Template.BlockInfo, MovementContext> actor) {
public ActorInstance createActor(Pair<Template.BlockInfo, MovementContext> 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);

View File

@ -44,10 +44,7 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
}
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<P extends BasicProgram> {
}
}
public <T extends TileEntity> void queueAdd(T tile) {
if (!Backend.canUseInstancing()) return;
queuedAdditions.add(tile);
}
public <T extends TileEntity> void update(T tile) {
if (!Backend.canUseInstancing()) return;
@ -144,6 +135,19 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
}
}
public synchronized <T extends TileEntity> 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);
}