Crash involving GLCapabilities and threads

Started by mickey695, July 31, 2016, 15:36:26

Previous topic - Next topic

mickey695

Hello guys, I am fairly new to LWJGL 3 and GLFW so I am probably making "noobish" mistakes.
I am experiencing a crash when attempting to create a GLCapabilities instance on a thread that is not the main thread

The code causing the crash is the first two lines of my run method in the rendering thread
@Override
public void run(){

     glfwMakeContextCurrent(window);
     this.glc = GL.createCapabilities();
     .
     .
     .
}


window is the long returned by the call to glfwCreateWindow on the main thread

This is the stack trace from the eclipse console:
Exception in thread "RenderingThread" java.util.MissingFormatArgumentException: Format specifier '%X'
	at java.util.Formatter.format(Formatter.java:2519)
	at java.util.Formatter.format(Formatter.java:2455)
	at java.lang.String.format(String.java:2940)
	at org.lwjgl.opengl.GL.createCapabilities(GL.java:326)
	at org.lwjgl.opengl.GL.createCapabilities(GL.java:296)
	at net.mickey695.main.RenderThread.run(RenderThread.java:30)


From the message I assume that there is a call that I must make on the current thread to put some variable on the stack, however I have no clue what is it.

Any help would be appreciated !


Nazerak

I think I'm encountering the same crash.  I just ported my code from last year to the most recent stable version of LWJGL and I'm getting a virtual machine crash after the program launches. 

I downloaded the nightly build but the file structure appears different from the stable build.  What do I need to do in order to swap over to the nightly build? 


Edit:

I've since gotten Eclipse configured to use the most recently Nightly build by adding the external JARs for lwjgl, GLFW, and OpenGL from that archive.  When I try to run my program (which ran using the initial release 3.0.0 version of LWJGL last year) after modifying the code to the newest syntax I experience a JVM crash according to the Eclipse console.  It's giving me an exception access violation and references the window thread I am using to operate my graphics window. 

I've read that you cannot call GL.createCapabilities on a thread other than the main thread.  I have called glfwMakeContextCurrent() using the glfw window's id number prior to this call.  Am I just using this wrong?  Do I need to create the window and do all of the initialization on the main thread instead before handing it over? 

Nazerak

As a follow-up to the previous edit I added the code for the Getting Started HelloWorld code in a separate class to my existing project to make sure there wasn't an issue with the installation of LWJGL and Java.  By itself the HelloWorld code works just fine and displays the expected red colored window and closes on escape press. 

My suspicion is that there is some problem running some particular code on a separate thread other than the main thread but I'm not sure what that would be. Something that has changed between LWJGL 3.0 revisions.

Is there a generally accepted way to create GLFW windows and then handle their rendering on a separate thread?

spasi

Quote from: Nazerak on August 17, 2016, 11:17:25Is there a generally accepted way to create GLFW windows and then handle their rendering on a separate thread?

Yes, it is very well explained in the GLFW documentation. Short LWJGL sample here (important note: the concurrency primitives used and general code setup are not representative of what a real app should look like).

In general, most GLFW functions may only be called from the main thread. This includes window creation, the event loop and event handling. You can of course make OpenGL contexts current in secondary threads, but window/context lifecycle must be coordinated with the main thread.

Btw, the GLFW bindings come with a lot of javadoc. You'll find a note on each method that says whether it is callable only from the main thread or not.