Made server exit on libGDX crash

This commit is contained in:
Anuken
2018-01-28 23:28:15 -05:00
parent fabc02f6ef
commit b7acab42b1

View File

@ -7,14 +7,16 @@ import io.anuke.mindustry.MindustryServer;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.util.Log;
import java.lang.reflect.Method;
public class ServerLauncher{
public static void main(String[] args){
public static void main(String[] args) throws Exception{
Net.setClientProvider(new KryoClient());
Net.setServerProvider(new KryoServer());
new HeadlessApplication(new MindustryServer()){
HeadlessApplication app = new HeadlessApplication(new MindustryServer()){
@Override
public boolean executeRunnables() {
try {
@ -27,5 +29,29 @@ public class ServerLauncher{
}
};
Method method = app.getClass().getDeclaredMethod("mainLoop");
method.setAccessible(true);
//kill default libGDX thread
for(Thread thread : Thread.getAllStackTraces().keySet()){
if(thread.getName().equals("\"HeadlessApplication\"")){
thread.interrupt();
}
}
//replace it with my own
Thread mainLoopThread = new Thread("HeadlessApplication") {
@Override
public void run () {
try {
method.invoke(app);
} catch (Throwable t) {
t.printStackTrace();
System.exit(-1);
}
}
};
mainLoopThread.start();
}
}