Lots of LWJGL crashes lately.

Started by orange451, January 10, 2017, 01:11:00

Previous topic - Next topic

orange451

About a year ago, when I first tried lwjgl3, I didn't have many issues with crashing. However, lately on both the stable and unstable branches, the JVM tends to crash a lot.

I get these kinds of errors in my projects folder:
http://pastebin.com/zTBxQ4Et

If it's something I am doing wrong, let me know. hah. Not sure where to start looking.

spasi

LWJGL 3.1.1 has a new implementation for calling OpenGL and OpenGL ES functions. This implementation stores context function pointers in internal JVM state, which is readily available when making a JNI method call. The benefit is that it completely eliminates thread-local lookups when calling GL/GLES functions.

One major trade-off is that function pointers are not checked anymore before LWJGL calls them (like always running with -Dorg.lwjgl.util.NoChecks=true). This means that if you call a function not exposed by the GL/GLES context, or if you call a function in a thread with no context current, you will get a crash.

It looks like the later is what's happening in your case. Judging by the stacktrace, you're calling glGetUniformLocation in a finalizer. Finalizers run in the "Finalizer" thread, which doesn't have an OpenGL context current. You would get an exception before LWJGL 3.1.1, but now you get a crash instead.

orange451

I see that stack trace, but it confuses me.

The application crashes mid-use, but the stacktrace comes from the GameShader.finalize() method which is ran on startup.

Kai

What makes you think that GameShader.finalize() is being run on startup? Do you call this method manually in your own code?
If so, then be aware that the JVM also calls this method, like Spasi said, by the JVM's special/dedicated finalizer system-thread. You cannot control when that happens. It just happens at some point when that object is about to be garbage-collected by the JVM, thus the following lines in the stack trace:
...
J 676 C1 java.lang.ref.Finalizer.runFinalizer(Lsun/misc/JavaLangAccess;)V (62 bytes) @ 0x0000000002a04794 [0x0000000002a04200+0x594]
J 675 C1 java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;Lsun/misc/JavaLangAccess;)V (6 bytes) @ 0x0000000002a03e9c [0x0000000002a03e40+0x5c]
j  java.lang.ref.Finalizer$FinalizerThread.run()V+45
v  ~StubRoutines::call_stub

orange451

Oh wow. I totally forgot there was a finalize method in java objects.
hah.

Funny that I've never run into any issues before.

Evan407

Quote from: orange451 on January 10, 2017, 01:11:00
About a year ago, when I first tried lwjgl3, I didn't have many issues with crashing. However, lately on both the stable and unstable branches, the JVM tends to crash a lot.

I get these kinds of errors in my projects folder:
http://pastebin.com/zTBxQ4Et

If it's something I am doing wrong, let me know. hah. Not sure where to start looking.
I get those too when I'm abusing buffers.