Hello Guest

Program Crashes

  • 2 Replies
  • 1981 Views
Program Crashes
« 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)

 ???

*

Offline abcdef

  • ****
  • 320
Re: Program Crashes
« Reply #1 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.

Code: [Select]
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);

Re: Program Crashes
« Reply #2 on: August 30, 2015, 12:56:03 »
Thanks I got it to work. :)