Skip to content

Commit 15da6a8

Browse files
committed
Merge pull request #96 from rzats/feature-CrashReporter
CrashReporter integration
2 parents 3ebeb1b + edffda1 commit 15da6a8

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## General
2+
*.log
23
hs_err_pid*
34
.gradle
45
/config/metrics

desktop/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
1313
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
1414
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
15+
compile "org.terasology:CrashReporter-destsol:3.0.0"
1516
}
1617

1718
task run(type: JavaExec) {
@@ -74,4 +75,4 @@ task afterEclipseImport(description: "Post processing after project generation",
7475
printer.setPreserveWhitespace(true)
7576
printer.print(classpath)
7677
}
77-
}
78+
}

desktop/src/org/destinationsol/desktop/SolDesktop.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
import org.destinationsol.SolFileReader;
99
import org.destinationsol.game.DebugOptions;
1010
import org.destinationsol.soundtest.SoundTestListener;
11-
import org.lwjgl.Sys;
11+
import org.terasology.crashreporter.CrashReporter;
1212

1313
import java.io.BufferedReader;
1414
import java.io.FileReader;
1515
import java.io.IOException;
1616
import java.io.PrintWriter;
1717
import java.io.StringWriter;
18+
import java.nio.charset.Charset;
19+
import java.nio.file.Path;
1820
import java.nio.file.Paths;
21+
import java.text.SimpleDateFormat;
1922
import java.util.ArrayList;
23+
import java.util.Arrays;
24+
import java.util.Date;
2025
import java.util.List;
2126

2227
public class SolDesktop {
@@ -59,20 +64,45 @@ public static void main(String[] argv) {
5964
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
6065
@Override
6166
public void uncaughtException(Thread thread, final Throwable ex) {
67+
// Get the exception stack trace string
6268
StringWriter stringWriter = new StringWriter();
6369
PrintWriter printWriter = new PrintWriter(stringWriter);
6470
ex.printStackTrace(printWriter);
71+
String exceptionString = stringWriter.getBuffer().toString();
6572

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();
6985
}
7086
});
7187

7288
new LwjglApplication(new SolApplication(), c);
7389
}
7490

7591
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+
76106
@Override
77107
public List<String> read(String fileName) {
78108
if (DebugOptions.DEV_ROOT_PATH != null) {

main/src/org/destinationsol/SolApplication.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@
2828
import org.destinationsol.game.SolGame;
2929
import org.destinationsol.game.sound.MusicManager;
3030
import org.destinationsol.menu.MenuScreens;
31-
import org.destinationsol.ui.*;
31+
import org.destinationsol.ui.DebugCollector;
32+
import org.destinationsol.ui.FontSize;
33+
import org.destinationsol.ui.SolInputManager;
34+
import org.destinationsol.ui.SolLayouts;
35+
import org.destinationsol.ui.UiDrawer;
3236

3337
import java.io.PrintWriter;
3438
import java.io.StringWriter;
39+
3540
public class SolApplication implements ApplicationListener {
3641

3742
private SolInputManager myInputMan;
@@ -111,6 +116,10 @@ private void safeUpdate() {
111116
PrintWriter pw = new PrintWriter(sw);
112117
t.printStackTrace(pw);
113118
myFatalErrorTrace = sw.toString();
119+
120+
if (!myReallyMobile) {
121+
throw t;
122+
}
114123
}
115124
}
116125

main/src/org/destinationsol/SolFileReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package org.destinationsol;
1818

19+
import java.nio.file.Path;
1920
import java.util.List;
2021

2122
public interface SolFileReader {
22-
List<String> read(String fileName);
23+
Path create(String fileName, List<String> lines);
24+
25+
List<String> read(String fileName);
2326
}

0 commit comments

Comments
 (0)