LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 628 forks source link

loading AWT Font causes glfwPollEvents() to never return #976

Closed mirraj2 closed 2 months ago

mirraj2 commented 2 months ago

Version

3.3.3

Platform

macOS arm64

JDK

JDK 11

Module

LWJGL

Bug description

  1. copy paste the HelloWorld code from https://www.lwjgl.org/guide
  2. Insert this line of code as the first line inside the main() method: new java.awt.Font("Arial", java.awt.Font.PLAIN, 14).toString();
  3. Run the program
  4. Try to close the window by clicking on the X in the corner

Actual: the window does not close. As a matter of fact, the game loop has stopped running entirely because glfwPollEvents() is blocking forever

Expected: I expect that I should be able to load AWT classes without everything dying.

Stacktrace or crash log output

No response

Spasi commented 2 months ago

Hey @mirraj2,

GLFW is not compatible with AWT on macOS. They both need to claim the main thread event loop and, depending on which is initialized first, one breaks the other. LWJGL offers alternative bindings for loading fonts (stb_truetype, freetype, harfbuzz) and images (stb_image, KTX).

LWJGL also ships an alternative GLFW implementation, which handles all windowing system events asynchronously. It can be enabled by setting GLFW_LIBRARY_NAME to glfw_async (or with -Dorg.lwjgl.glfw.libname=glfw_async). You may have better luck with that if you cannot avoid AWT.

mirraj2 commented 2 months ago

thank you @Spasi