Program Crashes

Started by technik3k, August 30, 2015, 02:34:12

Previous topic - Next topic

technik3k

I was trying to detect key press. The program worked then crashed. The error message was...

Exception in thread "main" org.lwjgl.system.libffi.ClosureError: Callback failed because the closure instance has been garbage collected.
   at org.lwjgl.glfw.GLFW.glfwPollEvents(Native Method)
   at Main.Test_Frame.main(Test_Frame.java:35)

???

abcdef

you need to have an instance of the call back that isn;t garbage collectable. To do this you need to store an instance of the call back at all times. In the example below you'll notice anonymous inner classes are not used.

private final GLFWCharCallback charCallback;

charCallback = new GLFWCharCallback()
        {
            @Override
            public void invoke(long window, int codepoint)
            {
               // do key processing
            }
        };

// create window
long window  = -1;
...your code here to create the window

GLFW.glfwSetCharCallback(window, charCallback);

technik3k

Thanks I got it to work. :)