Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGdx + IntellIJ + Mac OS = IllegalStateException: GLFW windows may only be cre  (Read 771 times)
0 Members and 1 Guest are viewing this topic.
Offline P0jahn

Senior Devvie


Medals: 1
Projects: 3



« Posted 2018-03-11 14:09:12 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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?
Offline zngga
« Reply #1 - Posted 2018-03-11 14:15:07 »

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

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


Maybe that will help.

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

My code never has bugs... it just develops unexpected features!
Offline KaiHH

JGO Kernel


Medals: 577



« Reply #2 - Posted 2018-03-11 14:16:31 »

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.
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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline P0jahn

Senior Devvie


Medals: 1
Projects: 3



« Reply #3 - Posted 2018-03-11 15:00:28 »

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.
Offline Spasi
« Reply #4 - Posted 2018-03-11 15:13:52 »

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.

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

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

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?
Offline P0jahn

Senior Devvie


Medals: 1
Projects: 3



« Reply #5 - Posted 2018-03-11 15:44:33 »

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!
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1250 views)
2018-06-10 19:43:48

EgonOlsen (1118 views)
2018-06-10 19:43:44

EgonOlsen (859 views)
2018-06-10 19:43:20

DesertCoockie (1268 views)
2018-05-13 18:23:11

nelsongames (1101 views)
2018-04-24 18:15:36

nelsongames (1330 views)
2018-04-24 18:14:32

ivj94 (2071 views)
2018-03-24 14:47:39

ivj94 (1224 views)
2018-03-24 14:46:31

ivj94 (2164 views)
2018-03-24 14:43:53

Solater (788 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!