LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Lots of LWJGL crashes lately.  (Read 1020 times)

orange451

  • Newbie
  • *
  • Offline Offline
  • Posts: 27
Lots of LWJGL crashes lately.
« 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.
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1888
Re: Lots of LWJGL crashes lately.
« Reply #1 on: January 10, 2017, 08:32:58 »

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.
Logged

orange451

  • Newbie
  • *
  • Offline Offline
  • Posts: 27
Re: Lots of LWJGL crashes lately.
« Reply #2 on: January 10, 2017, 22:55:06 »

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.
Logged

Kai

  • Guest
Re: Lots of LWJGL crashes lately.
« Reply #3 on: January 10, 2017, 23:03:54 »

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:
Code: [Select]
...
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
Logged

orange451

  • Newbie
  • *
  • Offline Offline
  • Posts: 27
Re: Lots of LWJGL crashes lately.
« Reply #4 on: January 11, 2017, 00:23:25 »

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

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

Evan407

  • Newbie
  • *
  • Offline Offline
  • Posts: 42
Re: Lots of LWJGL crashes lately.
« Reply #5 on: January 13, 2017, 22:01:08 »

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.
Logged