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(
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.createGlfwWindow(
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.createWindow(
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(
	at mygame.desktop.GameLauncher.launch(
	at mygame.desktop.redguyruns.gui.MainClass.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>(
	... 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.

Sounds like something is initializing AWT, which is not compatible with GLFW.

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!