LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: technik3k on August 30, 2015, 02:34:12

Title: Program Crashes
Post by: technik3k on August 30, 2015, 02:34:12
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)

???
Title: Re: Program Crashes
Post by: abcdef on August 30, 2015, 05:53:00
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);
Title: Re: Program Crashes
Post by: technik3k on August 30, 2015, 12:56:03
Thanks I got it to work. :)