Error causes application to run indefinitely

When running JME3 on macOS HighSierra using the lwjgl3 runtime dependency and no VM arguments (through gradle), the application prints the following error message.

	at org.lwjgl.glfw.GLFW.glfwCreateWindow(
	at com.jme3.system.lwjgl.LwjglWindow.createContext(
	at com.jme3.system.lwjgl.LwjglWindow.initInThread(
	at com.jme3.system.lwjgl.LwjglWindow.create(
	at mcclean.jetpack.HelloJME3.main(
Caused by: java.lang.IllegalStateException: GLFW windows may only be created on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. For offscreen rendering, make sure another window toolkit (e.g. AWT or JavaFX) is initialized before GLFW.
	at org.lwjgl.glfw.EventLoop$OffScreen.<clinit>(
	... 9 more

This isn’t very interesting, it’s expected rather. What is strange is the following message:

2018-03-01 16:41:22.286 java[7548:283829] !!! BUG: The current event queue and the main event queue are not the same. Events will not be handled correctly. This is probably because _TSGetMainThread was called for the first time off the main thread.

After spitting out these messages the application executes indefinitely.

When inspecting the debug perspective, the main thread is executing inside the native methodinitAppkit() from the class sun.lawt.macosx.LWCToolkit. (I could post what the other threads are doing but it does not seem relevant."

The most confusing behavior however is that this behavior only occurs when the SimpleApplication property of showSettings is set to false, and the initial settings dialog is not shown. When showSettings is set to true, the dialog window is shown, the program displays the first exception and then exits normally and the second error message (the one about the event queue) is not printed.

This seems like an error in the java surprisingly, if not for the change in behavior when the settings dialog is shown.

-macOS High Sierra 10.13.3 (Latest version as of post)
-JDK 9.0.1
-jMonkeyEngine 3.2-stable

Just a shot in the dark: Does it work with Java 8?

AWT doesn’t work with LWJGL 3. Since the settings dialog is AWT… well thats why it bugs out. That being said, you also need to pass a run time variable to force osx to start lwjgl 3 on the main thread. That’s as far as I’ve got with JME and lwjgl3 on osx. At that point for me it hard crashes out the session with no logging.

No, unfortunately it does not work with java 8. The problem is easily fixed by adding the -XstartOnFirstThread argument to the jvm, but that is not the issue I have, the issue is that I believe the application should terminate when the error occurs instead of running forever.

I don’t know how to get a thread dump on OSX… but that’s the next step I’d take. On Windows/Linux, it’s ctrl-brk from the command line that’s run the app.

I suspect AWT’s thread is still running or something.

Edit: actually it could be the lwjgl/render thread, too… that somehow doesn’t error out in a way that kills it.

I’ve created the following stack trace but I’m not sure how to make heads or tails of it. I believe the issue is as follows: GLFW initializes _TSGetMainThread off of the main thread. GLFW expects this to be the main thread. This makes sense with because the error is not printed when the display window is shown, probably because the AWT component of the settings display is used before the GLFW code.

Forgot the attachment! Stack Trace -

One more thing: It is almost certainly the GLFW calling the _TSGetMainThread on the wrong thread because creating a simple JFrame before starting the SimpleApplication also solves the problem. This fixes the issue even if the settings display is not shown. Perhaps I should show this issue to the makers of GLFW or LWJGL3?

I can run a LWJGL3 project by itself without running into any problems on OSX as long as xStartOnFirstThread is passed in. Running the jme lwjgl3, however, runs into problems. My guess is that jme is doing something funky that causes issues, but i’m not sure what yet.