Skip to content

Commit

Permalink
Fix chunk saving concurrent modification exception
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Jul 5, 2013
1 parent b85abbb commit 40aaa1b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/common/nallar/patched/storage/ThreadedChunkLoader.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Entity> 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
}
}
}
Expand Down

0 comments on commit 40aaa1b

Please sign in to comment.