Search code examples
javamacoslibgdxlwjglglfw

LWJGL glfwPollEvents blocks libGDX main loop on macOS


While my Lwjgl3Application-based game runs fine on windows and various linux distros, I only get a black screen on macOS. Looks like the call to glfwPollEvents does not return at all which blocks the main loop (see stacktrace).

I tried to provide a minium example but the issue doesn't happen with a fresh libGDX project using the same versions.

Stacktrace (the application doesn't crash but this is where it hangs):

invokeV:-1, JNI (org.lwjgl.system)
glfwPollEvents:3438, GLFW (org.lwjgl.glfw)
loop:199, Lwjgl3Application (com.badlogic.gdx.backends.lwjgl3)
<init>:167, Lwjgl3Application (com.badlogic.gdx.backends.lwjgl3)
main:43, DesktopLauncher

Versions:

  • java 11
  • macOS Sonama 14.5
  • libGDX 1.12.1
  • lwjgl 3.3.3

Edit:

  • I use -XstartOnFirstThread to start it so it's running in the main thread.
  • Toolkit.getDefaultToolkit().systemClipboard does not get called in the project nor anything else for java.awt or similar

Solution

  • Okay I removed parts of the application one by one and I was able to boil it down to the TexturePacker which I ran ad-hoc (for development purposes only) in my DesktopLauncher before starting the game. Skipping this step solves the problem.

    I didn't debug it deep enough yet to find the exact place in the TexturePacker that causes the issue but I've seen that it makes use of the java.awt package which also provides the problematic Toolkit.systemClipboard mentioned by ALUFTW.

    (Regarding the close-votes and down-votes for this question. I agree that there wasn't enough info to solve the problem but maybe the question and my answer helps somebody solving similar issues in the future so I decided to not delete it.)