Class StartupHelper

java.lang.Object
io.github.team6ENG.EscapeUni.lwjgl3.StartupHelper

public class StartupHelper extends 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
  • Method Details

    • startNewJvmIfRequired

      public 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

      public 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