Fix NPE when the game launched and suddenly crashes

This commit is contained in:
huangyuhui 2018-06-30 21:36:57 +08:00
parent 75031a04cc
commit 34f7774ce9
2 changed files with 16 additions and 7 deletions

View File

@ -172,13 +172,17 @@ public final class LauncherHelper {
@Override
public void onStop(boolean success, TaskExecutor executor) {
if (!success) {
if (!success && !Controllers.isStopped()) {
Platform.runLater(() -> {
// Check if the application has stopped
// because onStop will be invoked if tasks fail when the executor service shut down.
if (!Controllers.isStopped()) {
Controllers.closeDialog(launchingStepsPane);
if (executor.getLastException() != null)
Controllers.dialog(I18nException.getStackTrace(executor.getLastException()),
scriptFile == null ? Launcher.i18n("launch.failed") : Launcher.i18n("version.launch_script.failed"),
MessageBox.ERROR_MESSAGE);
}
});
}
launchingStepsPane.setExecutor(null);

View File

@ -157,7 +157,8 @@ public final class Controllers {
}
public static void closeDialog(Region content) {
if (stage == null) // shut down
return;
decorator.closeDialog(content);
}
@ -174,6 +175,10 @@ public final class Controllers {
getLeftPaneController().showUpdate();
}
public static boolean isStopped() {
return decorator == null;
}
public static void shutdown() {
mainPage = null;
settingsPage = null;