Potential fix for crash

This commit is contained in:
Jesse Boyd 2016-10-21 00:45:40 +11:00
parent d5ea46a29c
commit 8e91d8a6ad
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
7 changed files with 286 additions and 257 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ gradle.log
/bukkit18/build
build
/mvn
spigot-1.10

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.v1_10;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk;
@ -9,35 +10,12 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import net.minecraft.server.v1_10_R1.Block;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.ChunkSection;
import net.minecraft.server.v1_10_R1.DataBits;
import net.minecraft.server.v1_10_R1.DataPalette;
import net.minecraft.server.v1_10_R1.DataPaletteBlock;
import net.minecraft.server.v1_10_R1.DataPaletteGlobal;
import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.EntityTypes;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.TileEntity;
import java.util.*;
import net.minecraft.server.v1_10_R1.*;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_10_R1.CraftChunk;
@ -180,10 +158,18 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
if (count == 0) {
continue;
} else if (count >= 4096) {
entities[i].clear();
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
ents.clear();
}
}
} else {
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
char[] array = this.getIdArray(i);
Collection<Entity> ents = new ArrayList<>(entities[i]);
ents = new ArrayList<>(entities[i]);
synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) {
if (entity instanceof EntityPlayer) {
continue;
@ -200,8 +186,11 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
}
}
}
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (entsToRemove.size() > 0) {
if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
@ -211,9 +200,12 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
}
}
}
}
// Set entities
Set<UUID> createdEntities = new HashSet<>();
Set<CompoundTag> entitiesToSpawn = this.getEntities();
Set<UUID> createdEntities = new HashSet<>();
if (!entitiesToSpawn.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (CompoundTag nativeTag : entitiesToSpawn) {
Map<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
StringTag idTag = (StringTag) entityTagMap.get("Id");
@ -246,6 +238,8 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
createdEntities.add(entity.getUniqueID());
}
}
}
}
// Change task?
if (getParent().getChangeTask() != null) {
BukkitChunk_1_10 previous = getParent().getPrevious(this, sections, tiles, entities, createdEntities, false);

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.v1_7;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk;
@ -161,10 +162,18 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
if (count == 0) {
continue;
} else if (count >= 4096) {
entities[i].clear();
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
ents.clear();
}
}
} else {
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
char[] array = this.getIdArray(i);
Collection<Entity> ents = new ArrayList<>(entities[i]);
ents = new ArrayList<>(entities[i]);
synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) {
if (entity instanceof EntityPlayer) {
continue;
@ -172,7 +181,7 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
int x = ((int) Math.round(entity.locX) & 15);
int z = ((int) Math.round(entity.locZ) & 15);
int y = (int) Math.round(entity.locY);
if (array == null) {
if (array == null || y < 0 || y > 255) {
continue;
}
if (y < 0 || y > 255 || array[FaweCache.CACHE_J[y][z][x]] != 0) {
@ -181,9 +190,26 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
}
}
}
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity);
}
}
}
}
}
// Set entities
Set<UUID> createdEntities = new HashSet<>();
Set<CompoundTag> entitiesToSpawn = this.getEntities();
if (!entitiesToSpawn.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (CompoundTag nativeTag : entitiesToSpawn) {
Map<String, Tag> entityTagMap = nativeTag.getValue();
StringTag idTag = (StringTag) entityTagMap.get("Id");
@ -213,6 +239,8 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
createdEntities.add(entity.getUniqueID());
}
}
}
}
// Run change task if applicable
if (getParent().getChangeTask() != null) {
CharFaweChunk previous = getParent().getPrevious(this, sections, tiles, entities, createdEntities, false);
@ -251,17 +279,6 @@ public class BukkitChunk_1_7 extends CharFaweChunk<Chunk, BukkitQueue17> {
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (entsToRemove.size() > 0) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity);
}
}
}
}
// Set blocks
for (int j = 0; j < sections.length; j++) {
if (this.getCount(j) == 0) {

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.v1_8;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk;
@ -75,10 +76,18 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
if (count == 0) {
continue;
} else if (count >= 4096) {
entities[i].clear();
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
ents.clear();
}
}
} else {
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
char[] array = this.getIdArray(i);
Collection<Entity> ents = new ArrayList<>(entities[i]);
ents = new ArrayList<>(entities[i]);
synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) {
if (entity instanceof EntityPlayer) {
continue;
@ -86,7 +95,7 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
int x = ((int) Math.round(entity.locX) & 15);
int z = ((int) Math.round(entity.locZ) & 15);
int y = (int) Math.round(entity.locY);
if (array == null) {
if (array == null || y < 0 || y > 255) {
continue;
}
if (y < 0 || y > 255 || array[FaweCache.CACHE_J[y][z][x]] != 0) {
@ -95,9 +104,26 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
}
}
}
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity);
}
}
}
}
}
// Set entities
Set<UUID> createdEntities = new HashSet<>();
Set<CompoundTag> entitiesToSpawn = this.getEntities();
if (!entitiesToSpawn.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (CompoundTag nativeTag : entitiesToSpawn) {
Map<String, Tag> entityTagMap = nativeTag.getValue();
StringTag idTag = (StringTag) entityTagMap.get("Id");
@ -116,7 +142,7 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
Entity entity = EntityTypes.createEntityByName(id, nmsWorld);
if (entity != null) {
if (nativeTag != null) {
NBTTagCompound tag = (NBTTagCompound)BukkitQueue18R3.methodFromNative.invoke(BukkitQueue18R3.adapter, nativeTag);
NBTTagCompound tag = (NBTTagCompound) BukkitQueue18R3.methodFromNative.invoke(BukkitQueue18R3.adapter, nativeTag);
for (String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name);
}
@ -127,6 +153,8 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
createdEntities.add(entity.getUniqueID());
}
}
}
}
// Run change task if applicable
if (getParent().getChangeTask() != null) {
CharFaweChunk previous = getParent().getPrevious(this, sections, tiles, entities, createdEntities, false);
@ -165,17 +193,6 @@ public class BukkitChunk_1_8 extends CharFaweChunk<Chunk, BukkitQueue18R3> {
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (entsToRemove.size() > 0) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
if (entsToRemove.contains(entity.getUniqueID())) {
nmsWorld.removeEntity(entity);
}
}
}
}
// Set blocks
for (int j = 0; j < sections.length; j++) {
if (this.getCount(j) == 0) {

View File

@ -2,6 +2,7 @@ package com.boydti.fawe.bukkit.v1_9;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.bukkit.v0.BukkitQueue_0;
import com.boydti.fawe.example.CharFaweChunk;
import com.boydti.fawe.object.BytePair;
import com.boydti.fawe.object.FaweChunk;
@ -9,36 +10,12 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.internal.Constants;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import net.minecraft.server.v1_9_R2.Block;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.Blocks;
import net.minecraft.server.v1_9_R2.ChunkSection;
import net.minecraft.server.v1_9_R2.DataBits;
import net.minecraft.server.v1_9_R2.DataPalette;
import net.minecraft.server.v1_9_R2.DataPaletteBlock;
import net.minecraft.server.v1_9_R2.DataPaletteGlobal;
import net.minecraft.server.v1_9_R2.Entity;
import net.minecraft.server.v1_9_R2.EntityPlayer;
import net.minecraft.server.v1_9_R2.EntityTypes;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.NBTTagCompound;
import net.minecraft.server.v1_9_R2.TileEntity;
import java.util.*;
import net.minecraft.server.v1_9_R2.*;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Biome;
@ -183,10 +160,18 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
if (count == 0) {
continue;
} else if (count >= 4096) {
entities[i].clear();
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
ents.clear();
}
}
} else {
Collection<Entity> ents = entities[i];
if (!ents.isEmpty()) {
char[] array = this.getIdArray(i);
Collection<Entity> ents = new ArrayList<>(entities[i]);
ents = new ArrayList<>(entities[i]);
synchronized (BukkitQueue_0.adapter) {
for (Entity entity : ents) {
if (entity instanceof EntityPlayer) {
continue;
@ -203,8 +188,11 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
}
}
}
}
}
HashSet<UUID> entsToRemove = this.getEntityRemoves();
if (entsToRemove.size() > 0) {
if (!entsToRemove.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (int i = 0; i < entities.length; i++) {
Collection<Entity> ents = new ArrayList<>(entities[i]);
for (Entity entity : ents) {
@ -214,9 +202,12 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
}
}
}
}
// Set entities
Set<UUID> createdEntities = new HashSet<>();
Set<CompoundTag> entitiesToSpawn = this.getEntities();
Set<UUID> createdEntities = new HashSet<>();
if (!entitiesToSpawn.isEmpty()) {
synchronized (BukkitQueue_0.adapter) {
for (CompoundTag nativeTag : entitiesToSpawn) {
Map<String, Tag> entityTagMap = ReflectionUtils.getMap(nativeTag.getValue());
StringTag idTag = (StringTag) entityTagMap.get("Id");
@ -249,6 +240,8 @@ public class BukkitChunk_1_9 extends CharFaweChunk<Chunk, BukkitQueue_1_9_R1> {
createdEntities.add(entity.getUniqueID());
}
}
}
}
// Change task?
if (getParent().getChangeTask() != null) {
CharFaweChunk previous = getParent().getPrevious(this, sections, tiles, entities, createdEntities, false);

View File

@ -67,6 +67,8 @@ public class FaweTimer implements Runnable {
if (skip > 0) {
if (skipTick != tick) {
skip--;
skipTick = tick;
return true; // Run once per tick
}
return false;
}

View File

@ -61,9 +61,14 @@ public class SetQueue {
public void run() {
try {
double targetTPS = 18 - Math.max(Settings.QUEUE.EXTRA_TIME_MS * 0.05, 0);
while (!tasks.isEmpty() && Fawe.get().getTimer().isAbove(targetTPS)) {
tasks.poll().run();
do {
Runnable task = tasks.poll();
if (task != null) {
task.run();
} else {
break;
}
} while (Fawe.get().getTimer().isAbove(targetTPS));
if (inactiveQueues.isEmpty() && activeQueues.isEmpty()) {
lastSuccess = System.currentTimeMillis();
runEmptyTasks();