LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: h1 on September 06, 2015, 10:20:21

Title: LWJGL 3 - NullPointerException - MemoryUtil.memGlobalRefToObject
Post by: h1 on September 06, 2015, 10:20:21
After closing two windows in a row, the next Window which opens throws the following NullPointerException:

java.lang.NullPointerException
at org.lwjgl.system.MemoryUtil.memGlobalRefToObject(Native Method)
at org.lwjgl.system.libffi.Closure.create(Closure.java:195)
at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:554)


on opening a window i set up all the glfw stuff and the callbacks like this:

glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));


on close i only release all my callbacks as follows:

    public void onStop() {
        errorCallback.release();
        keyCallback.release();
        mouseButtonCallback.release();
        cursorPosCallback.release();
        scrollCallback.release();
        windowCloseCallback.release();
        windowSizeCallback.release();

        glfwDestroyWindow(window);
    }


It seemed that I solved this issue by simply not releasing the errorCallback in my onStop method:

    public void onStop() {
        //errorCallback.release();
        keyCallback.release();
        mouseButtonCallback.release();
        cursorPosCallback.release();
        scrollCallback.release();
        windowCloseCallback.release();
        windowSizeCallback.release();

        glfwDestroyWindow(window);
    }


Could anyone explain this to me or is this a bug?
Title: Re: LWJGL 3 - NullPointerException - MemoryUtil.memGlobalRefToObject
Post by: FortressBuilder on September 06, 2015, 10:30:29
The error callback is global and not per window, so you should only set it at the beginning and release it at the end of the program instead of every time a window is created or destroyed.
Title: Re: LWJGL 3 - NullPointerException - MemoryUtil.memGlobalRefToObject
Post by: h1 on September 06, 2015, 11:44:04
I see, thanks for the info  :)