From 4eabaffce7266f3efa6bb79821f54a38bb538ac8 Mon Sep 17 00:00:00 2001 From: shartte Date: Sun, 7 Jul 2024 01:14:50 +0200 Subject: [PATCH] Crash at most once after earlydisplay errors (#176) --- .../fml/earlydisplay/DisplayWindow.java | 26 ++++++++++--------- earlydisplay/src/main/resources/glfailure.txt | 13 ---------- 2 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 earlydisplay/src/main/resources/glfailure.txt diff --git a/earlydisplay/src/main/java/net/neoforged/fml/earlydisplay/DisplayWindow.java b/earlydisplay/src/main/java/net/neoforged/fml/earlydisplay/DisplayWindow.java index d88e7d90c..c0dd38f7f 100644 --- a/earlydisplay/src/main/java/net/neoforged/fml/earlydisplay/DisplayWindow.java +++ b/earlydisplay/src/main/java/net/neoforged/fml/earlydisplay/DisplayWindow.java @@ -10,9 +10,7 @@ import static org.lwjgl.opengl.GL32C.*; import java.awt.Desktop; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.net.URI; @@ -34,6 +32,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantLock; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; @@ -299,13 +298,10 @@ public String getGLVersion() { return this.glVersion; } + private final ReentrantLock crashLock = new ReentrantLock(); + private void crashElegantly(String errorDetails) { - String qrText; - try (var is = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/glfailure.txt")))) { - qrText = is.lines().collect(Collectors.joining("\n")); - } catch (IOException ioe) { - qrText = ""; - } + crashLock.lock(); // Crash at most once! StringBuilder msgBuilder = new StringBuilder(2000); msgBuilder.append("Failed to initialize the mod loading system and display.\n"); @@ -314,9 +310,9 @@ private void crashElegantly(String errorDetails) { msgBuilder.append(errorDetails); msgBuilder.append("\n\n"); msgBuilder.append("If you click yes, we will try and open " + ERROR_URL + " in your default browser"); - LOGGER.error("ERROR DISPLAY\n" + msgBuilder); + LOGGER.error("ERROR DISPLAY\n{}", msgBuilder); // we show the display on a new dedicated thread - Executors.newSingleThreadExecutor().submit(() -> { + var thread = new Thread(() -> { var res = TinyFileDialogs.tinyfd_messageBox("Minecraft: NeoForge", msgBuilder.toString(), "yesno", "error", false); if (res) { try { @@ -325,8 +321,14 @@ private void crashElegantly(String errorDetails) { TinyFileDialogs.tinyfd_messageBox("Minecraft: NeoForge", "Sadly, we couldn't open your browser.\nVisit " + ERROR_URL, "ok", "error", false); } } - System.exit(1); - }); + }, "crash-report"); + thread.setDaemon(true); + thread.start(); + try { + thread.join(); + } catch (InterruptedException ignored) {} + + System.exit(1); } /** diff --git a/earlydisplay/src/main/resources/glfailure.txt b/earlydisplay/src/main/resources/glfailure.txt deleted file mode 100644 index 4f5ee4aa8..000000000 --- a/earlydisplay/src/main/resources/glfailure.txt +++ /dev/null @@ -1,13 +0,0 @@ -█▀▀▀▀▀█ ▀▄▄▄▀█ █ █▀▀▀▀▀█ -█ ███ █ ███ ▀███▀ █ ███ █ -█ ▀▀▀ █ ▀ ▄ ███▀█ █ ▀▀▀ █ -▀▀▀▀▀▀▀ ▀ █ ▀ ▀▄█ ▀▀▀▀▀▀▀ -█▀█▀▄▄▀▄▀ █▄▀▄ ▀▀▀ ▄▀▀▀▄▀ -▄█▄▄ ▀▀███▀██▄ █▀ ▀▄▄ -▀█▄▀ ▀▀▄▄▀▀ █▀█▄▄████ ▀▀█ -▄▀▀▄▀ ▀▄▀▄█ ▀ ▀▀▀▄█ ▀▀▄ - ▀ ▀▀ ▄ ▄██▀ ▄█▀▀▀█▀█▀█ -█▀▀▀▀▀█ ▄█▄▄▀▀▄█ ▀ █ ▀▀▀ -█ ███ █ ▄▄ ▄ █ ▀██▀██▄██ -█ ▀▀▀ █ ██▄███▀█ █ █ █▀ -▀▀▀▀▀▀▀ ▀▀ ▀▀▀ ▀▀▀▀▀▀▀▀ \ No newline at end of file