Skip to content

Commit 3ca9e32

Browse files
authored
Stop burying the error due to things catching RuntimeExceptions.... (#1767)
1 parent efbca29 commit 3ca9e32

3 files changed

Lines changed: 75 additions & 8 deletions

File tree

lwjgl3-backend/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ dependencies {
7474
// LWJGL3
7575
implementation("org.lwjgl:lwjgl:${lwjglVersion}")
7676
implementation("org.lwjgl:lwjgl-opengl:${lwjglVersion}")
77+
compileOnly("org.lwjgl:lwjgl-sdl:${lwjglVersion}")
7778
runtimeOnly("org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives")
7879
runtimeOnly("org.lwjgl:lwjgl-opengl:$lwjglVersion:$lwjglNatives")
7980

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.gtnewhorizons.angelica.lwjgl3;
2+
3+
import static org.lwjgl.sdl.SDLMessageBox.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
4+
import static org.lwjgl.sdl.SDLMessageBox.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
5+
import static org.lwjgl.sdl.SDLMessageBox.SDL_MESSAGEBOX_ERROR;
6+
import static org.lwjgl.sdl.SDLMessageBox.SDL_ShowMessageBox;
7+
8+
import me.eigenraven.lwjgl3ify.api.Lwjgl3Aware;
9+
import me.eigenraven.lwjgl3ify.client.MainThreadExec;
10+
import org.lwjgl.sdl.SDL_MessageBoxButtonData;
11+
import org.lwjgl.sdl.SDL_MessageBoxData;
12+
import org.lwjgl.system.MemoryStack;
13+
14+
@Lwjgl3Aware
15+
public final class MissingDependencySdl {
16+
17+
private MissingDependencySdl() {}
18+
19+
public static void showFatal(String title, String message) {
20+
MainThreadExec.runOnMainThread(() -> showFatalOnMainThread(title, message));
21+
}
22+
23+
private static void showFatalOnMainThread(String title, String message) {
24+
try (MemoryStack stack = MemoryStack.stackPush()) {
25+
final SDL_MessageBoxData box = SDL_MessageBoxData.calloc(stack);
26+
box.flags(SDL_MESSAGEBOX_ERROR);
27+
box.title(stack.UTF8(title));
28+
box.message(stack.UTF8(message));
29+
30+
final SDL_MessageBoxButtonData.Buffer buttons = SDL_MessageBoxButtonData.calloc(1, stack);
31+
buttons.get(0).set(
32+
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT | SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
33+
0,
34+
stack.UTF8("OK"));
35+
box.buttons(buttons);
36+
37+
SDL_ShowMessageBox(box, null);
38+
}
39+
}
40+
}

src/main/java/com/gtnewhorizons/angelica/loading/AngelicaClientTweaker.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.gtnewhorizons.angelica.glsm.loading.DependencyVerifier;
1212
import com.gtnewhorizons.angelica.glsm.loading.EcosystemNarrowRules;
1313
import com.gtnewhorizons.angelica.loading.fml.compat.CompatHandlers;
14+
import com.gtnewhorizons.angelica.lwjgl3.MissingDependencySdl;
1415
import com.gtnewhorizons.angelica.mixins.Mixins;
1516
import com.gtnewhorizons.retrofuturabootstrap.SharedConfig;
1617
import cpw.mods.fml.relauncher.FMLLaunchHandler;
@@ -29,6 +30,8 @@
2930
import org.spongepowered.asm.launch.GlobalProperties;
3031
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
3132

33+
import javax.swing.JOptionPane;
34+
import java.awt.GraphicsEnvironment;
3235
import java.util.ArrayList;
3336
import java.util.Arrays;
3437
import java.util.List;
@@ -101,14 +104,37 @@ private static void addLwjgl3ifyExclusions() {
101104
}
102105

103106
private static void verifyDependencies() {
104-
DependencyVerifier.verify(AngelicaTweaker.class, List.of(
105-
new DependencyVerifier.Check(
106-
"/it/unimi/dsi/fastutil/ints/Int2ObjectMap.class",
107-
"Missing dependency: Angelica requires GTNHLib! Download: https://modrinth.com/mod/gtnhlib"),
108-
new DependencyVerifier.Check(
109-
"/com/gtnewhorizon/gtnhlib/client/renderer/VertexCallbackManager.class",
110-
"GTNHLib is outdated: Angelica requires GTNHLib 0.10.0 or newer! Download: https://modrinth.com/mod/gtnhlib")
111-
));
107+
try {
108+
DependencyVerifier.verify(AngelicaTweaker.class, List.of(
109+
new DependencyVerifier.Check(
110+
"/it/unimi/dsi/fastutil/ints/Int2ObjectMap.class",
111+
"Missing dependency: Angelica requires GTNHLib! Download: https://modrinth.com/mod/gtnhlib"),
112+
new DependencyVerifier.Check(
113+
"/com/gtnewhorizon/gtnhlib/client/renderer/VertexCallbackManager.class",
114+
"GTNHLib is outdated: Angelica requires GTNHLib 0.10.0 or newer! Download: https://modrinth.com/mod/gtnhlib")
115+
));
116+
} catch (RuntimeException ex) {
117+
fatalDependencyError(ex.getMessage());
118+
}
119+
}
120+
121+
private static void fatalDependencyError(String message) {
122+
final String title = "Angelica - Missing Dependency";
123+
System.err.println("FATAL: " + message);
124+
try {
125+
LOGGER.fatal(message);
126+
} catch (Throwable ignored) {}
127+
128+
final int lwjgl3ifyMajor = ((Integer) Launch.blackboard.getOrDefault("lwjgl3ify:major-version", Integer.MIN_VALUE));
129+
try {
130+
if (lwjgl3ifyMajor >= 3) {
131+
MissingDependencySdl.showFatal(title, message);
132+
} else if (!GraphicsEnvironment.isHeadless()) {
133+
JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
134+
}
135+
} catch (Throwable ignored) {}
136+
137+
Runtime.getRuntime().halt(1);
112138
}
113139

114140
@Override

0 commit comments

Comments
 (0)