Catch exceptions in instance/chunk/entity ticks

This commit is contained in:
TheMode 2021-07-11 16:56:27 +02:00
parent 2bdc403fd0
commit 9db185f8a1
2 changed files with 19 additions and 5 deletions

View File

@ -14,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.LockSupport;
import java.util.function.Consumer;
import java.util.function.LongConsumer;
@ -102,8 +103,13 @@ public final class UpdateManager {
*/
private void serverTick(long tickStart) {
// Tick all instances
MinecraftServer.getInstanceManager().getInstances().forEach(instance ->
instance.tick(tickStart));
MinecraftServer.getInstanceManager().getInstances().forEach(instance -> {
try {
instance.tick(tickStart);
} catch (Exception e) {
MinecraftServer.getExceptionManager().handleException(e);
}
});
// Tick all chunks (and entities inside)
this.threadProvider.updateAndAwait(tickStart);

View File

@ -133,7 +133,11 @@ public abstract class ThreadProvider {
final Chunk chunk = chunkEntry.chunk;
if (!ChunkUtils.isLoaded(chunk))
return;
chunk.tick(time);
try {
chunk.tick(time);
} catch (Exception e) {
MinecraftServer.getExceptionManager().handleException(e);
}
final var entities = chunkEntry.entities;
if (!entities.isEmpty()) {
for (Entity entity : entities) {
@ -142,7 +146,11 @@ public abstract class ThreadProvider {
// #acquire() callbacks should be called here
lock.lock();
}
entity.tick(time);
try {
entity.tick(time);
} catch (Exception e) {
MinecraftServer.getExceptionManager().handleException(e);
}
}
}
});