LibGdx + IntellIJ + Mac OS = IllegalStateException: GLFW windows may only be cre

So I have been developing my game in a Windows environment using IntelliJ for a few years and everything have worked well.

Just switched to a Macbook Pro, cloned my project and tried to run it in IntelliJ and I get the following error:

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:1384)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.createGlfwWindow(Lwjgl3Application.java:425)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.createWindow(Lwjgl3Application.java:372)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:107)
	at mygame.desktop.GameLauncher.launch(GameLauncher.java:14)
	at mygame.desktop.redguyruns.gui.MainClass.main(MainClass.java:47)
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>(EventLoop.java:38)
	... 6 more
AL lib: (EE) alc_cleanup: 1 device not closed

The thing is that I do start my game in the main thread. mygame.desktop.GameLauncher.launch, as seen in the stack trace, is actually invoked from the main method.

Tried adding -XstartOnFirstThread as a VM argument in my run configuration, and the result was that the games launches, you hear the music for a second and then everything freezes and the window goes black.

Anyone know what’s causing this?

I don’t know if it will help in your specific situation, but on MacOS I make sure to set the awt.headless property

System.setProperty("java.awt.headless", Boolean.TRUE.toString());

Maybe that will help.

Though, I can’t imagine that libGDX isn’t doing this already.

No you do not. And no, the stacktrace does not show that. The stacktrace shows that you are spawning a new Thread in which you call GameLauncher.launch() which then eventually calls glfwCreateWindow().
The “main thread” is the thread that calls the public static void main(String[] args) method and spawning a new Thread does not make that thread the main thread, even if it was spawned from the main thread.
Most GLFW methods, including glfwInit and glfwCreateWindow, may only be called from the main thread.

Yes the stacktrace I posted was wrong. I updated first post with the correct log now(and still suffer from the same problem).

java.awt.headless thing didn’t work. Get same error message.

[quote=“P0jahn,post:1,topic:59368”]
Sounds like something is initializing AWT, which is not compatible with GLFW.

[quote=“P0jahn,post:4,topic:59368”]
It must be used in combination with -XstartOnFirstThread.

But the ideal solution would be to eliminate the AWT dependency. Do you use ImageIO, BufferedImage or anything like that?

Using XstartOnFirstThread in conjunction with java.awt.headless set to true solved the issue.

I did also use some awt classes, but those where Dimension and Point2D. Replaced those as well.

Thanks for the help!