libgdx/gdx-liftoff

"There was a problem restarting the JVM" - JAR does not launch on macOS without explicitly passing `-XstartOnFirstThread`

willowell opened this issue · 4 comments

Hello there!

First of all, thank you very much for this awesome tool! I'm re-exploring LibGDX after a very long, almost 7 year hiatus, so it's exciting to see all these cool new tools and libraries for working with LibGDX.

Unable to launch JAR without explicitly passing -XstartOnFirstThread

When launching the JAR via double-clicking or running java -jar gdx-liftoff-1.11.0.1.jar, I get the following message and NPE:

There was a problem restarting the JVM
java.lang.NullPointerException
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1092)
	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
	at gdx.liftoff.MainKt.startNewJvmIfRequired(main.kt:67)
	at gdx.liftoff.MainKt.main(main.kt:82)
	at gdx.liftoff.MainKt.main(main.kt)

This message originates from this try-catch block: https://github.com/tommyettinger/gdx-liftoff/blob/master/src/main/kotlin/gdx/liftoff/main.kt#L76-L87

Sounds like startNewJvmIfRequired() (https://github.com/tommyettinger/gdx-liftoff/blob/master/src/main/kotlin/gdx/liftoff/main.kt#L36) is supposed to be able to restart the JVM and append -XstartOnFirstThread if needed, but that is not happening here.

However, if I explicitly append -XstartOnFirstThread via java -XstartOnFirstThread -jar gdx-liftoff-1.11.0.1.jar, the JAR launches without issue.

Please let me know if there is any additional information I can provide to help diagnose this issue!

Diagnostic Info

OS: macOS 12.5
Arch: aarch64 / Apple Silicon M1
Java Version: 18.0.1, installed through https://adoptium.net/
Kotlin Version: 1.7.10 (JRE 18.0.1)

Heh, this was fixed, I think, in the very first commit after the last release. I haven't done a release since then (2 weeks ago), but you're the second person to mention this issue, so I might make a release soon to address it. I'm wondering if it has to do with Java 18, since the code that handles -XstartOnFirstThread was written at least a year ago, and Java 18 may have changed something with that process. I believe what the issue winds up being caused by is an environment variable that used to be set reliably on MacOS but isn't set by all JVMs anymore; this variable was used by the last stable release to figure out what the main class was. The current code that I'll release soon uses an additional fallback in case that fails, but it needs some more testing.

OK, this should be addressed in https://github.com/tommyettinger/gdx-liftoff/releases/tag/v1.11.0.2 ; it would be great if you could try the release and see if the -XstartOnFirstThread is handled correctly now.

Hello @tommyettinger! Sorry for the late reply - I will take a look later today and verify your fix on my end. Thank you so much for looking into this so quickly!!