Lwjgl3: Crashing on threads?

Created on 21 Aug 2017  路  12Comments  路  Source: LWJGL/lwjgl3

I am fairly new to using LWJGL, and I keep getting this error. From what I can tell from reading under the THREAD section in the log, it seems to crash on Thread.run()

Here is the log file IntelliJ spits out at me: hs_err_pid18639.log

Question

Most helpful comment

I guess that line 49 of Window.java is your error. You had this:

~java
this.windowHandle = glfwCreateWindow(this.width, this.height, this.title, 1, 0);
~

The fourth parameter is the monitor to use, and that is only used to make your window fullscreen on start. For other windows, it should be MemoryUtil.NULL or 0.

The error you are having is a SIGSEGV, which means that something got a segmentation fault, like accessing un-owned memory location, and that might be the unknown monitor handle.

To get the correct monitor handle, you have to use glfwGetPrimaryMonitor() function to get the ID of the primary monitor. Hope this helps.

All 12 comments

glfwCreateWindow (read the section "Thread safety") as well as a lot of other GLFW functions may _only_ be called in the _main_ thread (which is the thread that initially calls your main method).
Also make sure you call glfwInit before doing anything with GLFW (except setting its error callback via glfwSetErrorCallback).

I still get the same error for when I completely go away from starting on another thread.

Here is my recent push: https://github.com/BlakeBarnes00/Sandbox/commit/42c7571690ae3b77487c982df873aa894804ff58 it shows that I have removed the thread, and went straight to calling run(). Still getting the same error from within the inside of the function.

Thinking from the docs, I assume that main thread in that context means the thread that called the glfwInit() function right? Even after the change, it should work if that was the cause. He also do seem to set the GLFW error callback.

@BlakeBarnes00 Could you delete all the error logs and retry? Upload the new log after the rerun.

@sriharshachilakapati

new log
most recent commit

Remove the call to init() in the Window class constructor, it's already being initialized by the game engine. Did you try the native GLFW to verify if this is a problem of your system instead?

Can you run my game (self running fat jar) http://downloads.goharsha.com/ld38/PlanetDefenseDesktop.jar ?

I guess that line 49 of Window.java is your error. You had this:

~java
this.windowHandle = glfwCreateWindow(this.width, this.height, this.title, 1, 0);
~

The fourth parameter is the monitor to use, and that is only used to make your window fullscreen on start. For other windows, it should be MemoryUtil.NULL or 0.

The error you are having is a SIGSEGV, which means that something got a segmentation fault, like accessing un-owned memory location, and that might be the unknown monitor handle.

To get the correct monitor handle, you have to use glfwGetPrimaryMonitor() function to get the ID of the primary monitor. Hope this helps.

That was the fix! I can't believe I overlooked that this entire time. Thank you so much @sriharshachilakapati

Now try to get your threading code back into place. I'm sure running with thread is fine on non-mac machines which your initial code does in the gameEngine.start() method. I'm curious about this.

With gameEngine.start() it works now! Funny how one number can ruin an entire program, eh?

Good, as I believed, the main thread in this context is the thread that invoked glfwInit() and not the thread that ran your main method. This becomes the later on MacOS, because Cocoa doesn't allow two application event loops in a single application and that contradicts with the EDT of Swing/JavaFX. Congrats on getting this solved, and I guess we both learned a new thing.

I am still new to threading, so this did help me out a lot. Thank you so much!

Thanks @sriharshachilakapati for inspecting and solving this!
I've added a check for this potential error to https://github.com/LWJGLX/debug.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SpinyOwl picture SpinyOwl  路  3Comments

hoijui picture hoijui  路  7Comments

ShadowLordAlpha picture ShadowLordAlpha  路  3Comments

nickclark2016 picture nickclark2016  路  5Comments

EmpsThomy picture EmpsThomy  路  3Comments