From 40aaa1b22411e08a99993d9cc1117f28eac56b22 Mon Sep 17 00:00:00 2001 From: Ross Allan Date: Fri, 5 Jul 2013 22:24:45 +0100 Subject: [PATCH] Fix chunk saving concurrent modification exception Signed-off-by: Ross Allan --- .../patched/storage/ThreadedChunkLoader.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/common/nallar/patched/storage/ThreadedChunkLoader.java b/src/common/nallar/patched/storage/ThreadedChunkLoader.java index 04a8e9ca..91bd128a 100644 --- a/src/common/nallar/patched/storage/ThreadedChunkLoader.java +++ b/src/common/nallar/patched/storage/ThreadedChunkLoader.java @@ -4,6 +4,7 @@ import java.io.DataOutputStream; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.logging.Level; @@ -329,23 +330,26 @@ protected void writeChunkToNBT(Chunk par1Chunk, World par2World, NBTTagCompound Iterator iterator; for (i = 0; i < par1Chunk.entityLists.length; ++i) { - iterator = par1Chunk.entityLists[i].iterator(); - - while (iterator.hasNext()) { - Entity entity = (Entity) iterator.next(); - nbttagcompound1 = new NBTTagCompound(); - - try { - if (entity.addEntityID(nbttagcompound1)) { - par1Chunk.hasEntities = true; - nbttaglist1.appendTag(nbttagcompound1); + List entities = par1Chunk.entityLists[i]; + + synchronized (entities) { + iterator = entities.iterator(); + while (iterator.hasNext()) { + Entity entity = (Entity) iterator.next(); + nbttagcompound1 = new NBTTagCompound(); + + try { + if (entity.addEntityID(nbttagcompound1)) { + par1Chunk.hasEntities = true; + nbttaglist1.appendTag(nbttagcompound1); + } + } catch (Throwable t) { + FMLLog.log(Level.SEVERE, t, + "An Entity type %s at %s,%f,%f,%f has thrown an exception trying to write state. It will not persist. Report this to the mod author", + entity.getClass().getName(), + Log.name(entity.worldObj), + entity.posX, entity.posY, entity.posZ); // MCPC+ - add location } - } catch (Throwable t) { - FMLLog.log(Level.SEVERE, t, - "An Entity type %s at %s,%f,%f,%f has thrown an exception trying to write state. It will not persist. Report this to the mod author", - entity.getClass().getName(), - Log.name(entity.worldObj), - entity.posX, entity.posY, entity.posZ); // MCPC+ - add location } } }