Fixes to many multithreading crashes and freezes
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package io.anuke.kryonet;
|
||||
|
||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class DefaultThreadImpl implements ThreadProvider {
|
||||
private Thread thread;
|
||||
|
||||
@@ -47,4 +53,43 @@ public class DefaultThreadImpl implements ThreadProvider {
|
||||
public void notify(Object object) {
|
||||
object.notify();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Entity> void switchContainer(EntityGroup<T> group) {
|
||||
group.setContainer(new ConcurrentContainer<>());
|
||||
}
|
||||
|
||||
static class ConcurrentContainer<T> implements EntityContainer<T>{
|
||||
private CopyOnWriteArrayList<T> list = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(T item) {
|
||||
list.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(T item) {
|
||||
list.remove(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
return list.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return list.iterator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.anuke.mindustry.net.Streamable;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import org.java_websocket.WebSocket;
|
||||
import org.java_websocket.exceptions.WebsocketNotConnectedException;
|
||||
@@ -296,7 +297,7 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
private void handleException(Throwable e){
|
||||
Gdx.app.postRunnable(() -> { throw new RuntimeException(e);});
|
||||
Timers.run(0f, () -> { throw new RuntimeException(e);});
|
||||
}
|
||||
|
||||
KryoConnection getByKryoID(int id){
|
||||
|
||||
Reference in New Issue
Block a user