mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-29 22:27:54 +07:00
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.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();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user