|
8 | 8 | import org.destinationsol.SolFileReader; |
9 | 9 | import org.destinationsol.game.DebugOptions; |
10 | 10 | import org.destinationsol.soundtest.SoundTestListener; |
11 | | -import org.lwjgl.Sys; |
| 11 | +import org.terasology.crashreporter.CrashReporter; |
12 | 12 |
|
13 | 13 | import java.io.BufferedReader; |
14 | 14 | import java.io.FileReader; |
15 | 15 | import java.io.IOException; |
16 | 16 | import java.io.PrintWriter; |
17 | 17 | import java.io.StringWriter; |
| 18 | +import java.nio.charset.Charset; |
| 19 | +import java.nio.file.Path; |
18 | 20 | import java.nio.file.Paths; |
| 21 | +import java.text.SimpleDateFormat; |
19 | 22 | import java.util.ArrayList; |
| 23 | +import java.util.Arrays; |
| 24 | +import java.util.Date; |
20 | 25 | import java.util.List; |
21 | 26 |
|
22 | 27 | public class SolDesktop { |
@@ -59,20 +64,45 @@ public static void main(String[] argv) { |
59 | 64 | Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { |
60 | 65 | @Override |
61 | 66 | public void uncaughtException(Thread thread, final Throwable ex) { |
| 67 | + // Get the exception stack trace string |
62 | 68 | StringWriter stringWriter = new StringWriter(); |
63 | 69 | PrintWriter printWriter = new PrintWriter(stringWriter); |
64 | 70 | ex.printStackTrace(printWriter); |
| 71 | + String exceptionString = stringWriter.getBuffer().toString(); |
65 | 72 |
|
66 | | - String exceptionString = stringWriter.getBuffer().toString() + "Message: " + ex.getLocalizedMessage(); |
67 | | - System.err.println("Uncaught exception: " + exceptionString); |
68 | | - Sys.alert("Uncaught Exception", exceptionString); |
| 73 | + // Write to system.err |
| 74 | + System.err.println(exceptionString); |
| 75 | + |
| 76 | + // Create a crash dump file |
| 77 | + String fileName = "crash-" + new SimpleDateFormat("yyyy-dd-MM_HH-mm-ss").format(new Date()) + ".log"; |
| 78 | + List<String> lines = Arrays.asList(exceptionString); |
| 79 | + Path logPath = new MyReader().create(fileName, lines).toAbsolutePath().getParent(); |
| 80 | + |
| 81 | + // Run asynchronously so that the error message view is not blocked |
| 82 | + new Thread(() -> { |
| 83 | + CrashReporter.report(ex, logPath); |
| 84 | + }).start(); |
69 | 85 | } |
70 | 86 | }); |
71 | 87 |
|
72 | 88 | new LwjglApplication(new SolApplication(), c); |
73 | 89 | } |
74 | 90 |
|
75 | 91 | private static class MyReader implements SolFileReader { |
| 92 | + @Override |
| 93 | + public Path create(String fileName, List<String> lines) { |
| 94 | + if (DebugOptions.DEV_ROOT_PATH != null) { |
| 95 | + fileName = DebugOptions.DEV_ROOT_PATH + fileName; |
| 96 | + } |
| 97 | + Path file = Paths.get(fileName); |
| 98 | + try { |
| 99 | + java.nio.file.Files.write(file, lines, Charset.forName("UTF-8")); |
| 100 | + } catch (IOException e) { |
| 101 | + e.printStackTrace(); |
| 102 | + } |
| 103 | + return file; |
| 104 | + } |
| 105 | + |
76 | 106 | @Override |
77 | 107 | public List<String> read(String fileName) { |
78 | 108 | if (DebugOptions.DEV_ROOT_PATH != null) { |
|
0 commit comments