[BUG] Rare and Random crashes in my LWJGL game

Started by Lankyware, March 07, 2024, 12:46:46

Previous topic - Next topic


Ok so in my indie game, the game will randomly crash like once every 3 hours or so on average. It gives the message: A fatal error has been detected by the Java Runtime Environment. And it makes a log file. I've looked into it a lot and haven't been able to find out what causes this. This article is the closest I've found to an answer: https://inside.java/2020/12/03/crash-outside-the-jvm/
Error log file: https://gist.github.com/dfu1/253cc2f51b372027109dc99604b2c4ed
I've taken a look in the log file, and in the Java frames part it shows there was a call of org.lwjgl.opengl.GL11C.glDrawArrays(III)V.
And in the Internal exceptions, it says there's a java/lang/NoSuchMethodError exception.
I cannot figure out what the cause is, and I don't understand why it would be happening so rarely and randomly.
Any explanations/ideas are welcome.


Hey Lankyware,

Does it happen much earlier if you add System.gc() calls (say, once per frame) in your application? It would indicate that a direct ByteBuffer that is still in use is being garbage-collected, and its associated native memory freed, by mistake. Note that a major issue with GC-managed ByteBuffers (allocated with ByteBuffer.allocateDirect or BufferUtils in LWJGL) is that they are not freed unless full GC cycles happen. The JDK uses Cleaner for this, which is a PhantomReference. Weak/soft/phantom reference processing happens during full GC pauses with most GCs. Such pauses are kind of rare on modern JVMs and that can explain unpredictable crashes at a later time.

I hope this helps.


Oh, I stopped using ByteBuffers. When I call glBufferData() I put in an array of floats. IIRC I did this because for some things in my game, I put new data in before every draw call, and using Buffer objects for that made it GC more often, causing microlags.


I was able to stop the crashes. There were two different animation effects being batch rendered together, I split it into 2 separate draw calls and that got rid of the crashes for some reason.