Made server exit on libGDX crash
This commit is contained in:
@@ -7,14 +7,16 @@ import io.anuke.mindustry.MindustryServer;
|
|||||||
import io.anuke.mindustry.net.Net;
|
import io.anuke.mindustry.net.Net;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ServerLauncher{
|
public class ServerLauncher{
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args) throws Exception{
|
||||||
|
|
||||||
Net.setClientProvider(new KryoClient());
|
Net.setClientProvider(new KryoClient());
|
||||||
Net.setServerProvider(new KryoServer());
|
Net.setServerProvider(new KryoServer());
|
||||||
|
|
||||||
new HeadlessApplication(new MindustryServer()){
|
HeadlessApplication app = new HeadlessApplication(new MindustryServer()){
|
||||||
@Override
|
@Override
|
||||||
public boolean executeRunnables() {
|
public boolean executeRunnables() {
|
||||||
try {
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user