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.73k stars 632 forks source link

glfw causes program to hang #68

Closed thislooksfun closed 9 years ago

thislooksfun commented 9 years ago

If you try to create a new Font object or call ImageIO.read() (only two I've discovered so far) after calling GLFW.glfwCreateWindow, the program will hang—as far as I can tell—indefinitely.

My source code is here if it helps. Main class is here

FortressBuilder commented 9 years ago

Just in case there's an error with GLFW, you should set up an error callback.

public class SnakeGame {
    GLFWErrorCallback errorCallback;
    // ...
    private void init() {
        errorCallback = Callbacks.errorCallbackPrint();
        glfwSetErrorCallback(errorCallback);
        // ...
    }
}
octylFractal commented 9 years ago

I don't get this freeze on Windows -- possibly platform specific?

Cethric commented 9 years ago

The freeze also occurs on Mac (tested on OSX 10.10)

sriharshachilakapati commented 9 years ago

This is because using those objects will cause the AWT to run it's event loop, and on OSX, the main thread is already used by GLFW. The solution is to set the headless property of the AWT to true.

System.setProperty("java.awt.headless", "true");

Set that property before creating the window, then create the window. Also note that you have to create the fonts or the resources only after the window is created.

Spasi commented 9 years ago

LWJGL 3 is not compatible with AWT on Mac OS X. This has been discussed extensively in the LWJGL forum. Even though certain workarounds can work under very specific conditions, it is highly recommended to not use AWT/Swing with LWJGL 3.

For image loading and font rendering LWJGL 3 recently added STB bindings, you can use that instead of AWT. See these samples.