Package bytemusketeers.heslingtonhustle
Class StartupHelper
- java.lang.Object
-
- bytemusketeers.heslingtonhustle.StartupHelper
-
class StartupHelper extends java.lang.Object
Adds some utilities to ensure that the JVM was started with the-XstartOnFirstThread
argument, which is required on macOS for LWJGL 3 to function. Also helps on Windows when users have names with characters from outside the Latin alphabet, a common cause of startup crashes.
Based on this java-gaming.org post by kappa- Author:
- damios, ENG1 Team 23 (Cohort 3) - stylistic modifications
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
JVM_RESTARTED_ARG
The JVM command-line argument to indicate that the JVM is restarted
-
Constructor Summary
Constructors Modifier Constructor Description private
StartupHelper()
TheStartupHelper
must not be instantiated
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static boolean
startNewJvmIfRequired()
Starts a new JVM if the application was started on macOS without the-XstartOnFirstThread
argument.private static boolean
startNewJvmIfRequired(boolean redirectOutput)
Starts a new JVM if the application was started on macOS without the-XstartOnFirstThread
argument.
-
-
-
Constructor Detail
-
StartupHelper
private StartupHelper() throws java.lang.UnsupportedOperationException
TheStartupHelper
must not be instantiated- Throws:
java.lang.UnsupportedOperationException
-
-
Method Detail
-
startNewJvmIfRequired
private static boolean startNewJvmIfRequired(boolean redirectOutput)
Starts a new JVM if the application was started on macOS without the-XstartOnFirstThread
argument. This also includes some code for Windows, for the case where the user's home directory includes certain non-Latin-alphabet characters (without this code, most LWJGL3 apps fail immediately for those users). Returns whether a new JVM was started and thus no code should be executed.Usage:
public static void main(String... args) { if (StartupHelper.startNewJvmIfRequired(true)) return; // This handles macOS support and helps on Windows. // after this is the actual main method code }
- Parameters:
redirectOutput
- whether the output of the new JVM should be rerouted to the old JVM, so it can be accessed in the same place; keeps the old JVM running if enabled- Returns:
- whether a new JVM was started and thus no code should be executed in this one
-
startNewJvmIfRequired
static boolean startNewJvmIfRequired()
Starts a new JVM if the application was started on macOS without the-XstartOnFirstThread
argument. Returns whether a new JVM was started and thus no code should be executed. Redirects the output of the new JVM to the old one.Usage:
public static void main(String... args) { if (StartupHelper.startNewJvmIfRequired()) return; // This handles macOS support and helps on Windows. // the actual main method code }
- Returns:
- whether a new JVM was started and thus no code should be executed in this one
-
-