LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: bluevideogame on December 26, 2015, 19:54:27

Title: Help Please
Post by: bluevideogame on December 26, 2015, 19:54:27
I am on a macbook air using eclipse, and I follow the exact instructions from many videos to get this error. I am running the example code off the main website.

Hello LWJGL 3.0.0b SNAPSHOT!
Exception in thread "main" java.lang.ExceptionInInitializerError
   at org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:1248)
   at learningshit.HelloWorld.init(HelloWorld.java:55)
   at learningshit.HelloWorld.run(HelloWorld.java:24)
   at learningshit.HelloWorld.main(HelloWorld.java:111)
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:39)
   ... 4 more

Can anyone help me?
Title: Re: Help Please
Post by: Cornix on December 26, 2015, 20:13:11
QuoteGLFW 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.
Title: Re: Help Please
Post by: bluevideogame on December 26, 2015, 21:24:22
Quote from: Cornix on December 26, 2015, 20:13:11
QuoteGLFW 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.

What does that mean, how do I fix this?
Title: Re: Help Please
Post by: quew8 on December 26, 2015, 21:51:25
QuotePlease run the JVM with -XstartOnFirstThread.

You need to stick "-XstartOnFirstThread" as a runtime argument for Java. If you go into the properties of your Eclipse project there should be some kind of "runtime" options one of which should be something along the lines of "command line arguments." Put that there.
Title: Re: Help Please
Post by: bluevideogame on December 26, 2015, 22:32:09
Quote from: quew8 on December 26, 2015, 21:51:25
QuotePlease run the JVM with -XstartOnFirstThread.

You need to stick "-XstartOnFirstThread" as a runtime argument for Java. If you go into the properties of your Eclipse project there should be some kind of "runtime" options one of which should be something along the lines of "command line arguments." Put that there.

Thank you!
Went to Run -> Run Configuration -> Clicked on my project ->Arguements Tab -> VM Arguements -> Pasted -XstartOnFirstThread -> Clicked apply, and then run, and it worked!!!!!
Title: Re: Help Please
Post by: yoojeen on June 22, 2017, 08:57:14
some error.

Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
Caused by: java.lang.IllegalStateException: GLFW windows may only be created on the main thread.
   at org.lwjgl.glfw.EventLoop$OffScreen.<clinit>(EventLoop.java:37)
   ... 4 more

okay, it's works in main thread.

but what we do if client-server application engineering, and server part use main thread, and GUI needed in second thread for local run of app, or just use in main for app with implements Runnable (runnable make another thread) ????

is this a hard/soft restriction or bug? with what is connected? can i work around it?
Title: Re: Help Please
Post by: spasi on June 22, 2017, 09:08:00
This is a macOS limitation and it is per process. If you need multiple event loops for some reason, then you'd have to launch your application multiple times and use an IPC mechanism to talk to each other.
Title: Re: Help Please
Post by: yoojeen on June 22, 2017, 11:50:20
yep, i use MacOS.

i want launch application multiple times, but communication with each other is not needed (tcp/udp only if its a game), it must be separate instances, just needed a graphics in a Runnable class