Trouble with Callbacks.

Started by Risa123, April 01, 2018, 15:16:38

Previous topic - Next topic

Risa123

LWJGL is saying that i have memory leaks even when im using Callbacks.glfwFreeCallbacks

spasi

glfwFreeCallbacks only frees callbacks associated with the specified window handle. The error, monitor and joystick callbacks must be freed separately.

If that doesn't help, check if you're using a window content scale callback. I just noticed that it's not being handled in glfwFreeCallbacks (will be fixed in next 3.1.7 snapshot).

Risa123

 Ok to be more specifik the log says this
Exception in thread "main" java.lang.IllegalStateException: The memory address specified is not being tracked
	at org.lwjgl.system.MemoryManage$DebugAllocator.untrack(MemoryManage.java:192)
	at org.lwjgl.system.MemoryManage$DebugAllocator.free(MemoryManage.java:153)
	at org.lwjgl.system.MemoryUtil.nmemFree(MemoryUtil.java:254)
	at org.lwjgl.system.Struct.free(Struct.java:47)
	at cz.risa.lwjglengine.engine.object2d.Painter.destroy(Painter.java:63)
	at cz.risa.lwjglengine.engine.object2d.Canvas.destroy(Canvas.java:39)
	at cz.risa.lwjglengine.engine.LWJGLApplication.destroy(LWJGLApplication.java:107)
	at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:163)
	at cz.risa.testproject.Main.main(Main.java:37)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1D660000
	at org.lwjgl.system.Callback.create(Callback.java:133)
	at org.lwjgl.system.CallbackI.address(CallbackI.java:34)
	at org.lwjgl.system.MemoryUtil.memAddressSafe(MemoryUtil.java:727)
	at org.lwjgl.glfw.GLFW.glfwSetCursorEnterCallback(GLFW.java:3733)
	at cz.risa.lwjglengine.engine.MouseInput.init(MouseInput.java:36)
	at cz.risa.lwjglengine.engine.LWJGLApplication.init(LWJGLApplication.java:97)
	at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:140)
	at cz.risa.testproject.Main.main(Main.java:37)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x47FE20
	at org.lwjgl.system.Struct.__malloc(Struct.java:88)
	at org.lwjgl.glfw.GLFWImage.malloc(GLFWImage.java:167)
	at cz.risa.lwjglengine.engine.LWJGLApplication.setIcon(LWJGLApplication.java:215)
	at cz.risa.testproject.Main.main(Main.java:36)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1D670000
	at org.lwjgl.system.Callback.create(Callback.java:133)
	at org.lwjgl.system.CallbackI.address(CallbackI.java:34)
	at org.lwjgl.system.MemoryUtil.memAddressSafe(MemoryUtil.java:727)
	at org.lwjgl.glfw.GLFW.glfwSetMouseButtonCallback(GLFW.java:3674)
	at cz.risa.lwjglengine.engine.MouseInput.init(MouseInput.java:39)
	at cz.risa.lwjglengine.engine.LWJGLApplication.init(LWJGLApplication.java:97)
	at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:140)
	at cz.risa.testproject.Main.main(Main.java:37)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1DB0000
	at org.lwjgl.system.Callback.create(Callback.java:133)
	at org.lwjgl.system.Callback.<init>(Callback.java:83)
	at org.lwjgl.glfw.GLFWWindowSizeCallback.<init>(GLFWWindowSizeCallback.java:56)
	at cz.risa.lwjglengine.engine.LWJGLApplication$WindowSizeCallback.<init>(LWJGLApplication.java:222)
	at cz.risa.lwjglengine.engine.LWJGLApplication$WindowSizeCallback.<init>(LWJGLApplication.java:222)
	at cz.risa.lwjglengine.engine.LWJGLApplication.<init>(LWJGLApplication.java:44)
	at cz.risa.testproject.Main.main(Main.java:35)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1DC0000
	at org.lwjgl.system.Callback.create(Callback.java:133)
	at org.lwjgl.system.Callback.<init>(Callback.java:83)
	at org.lwjgl.glfw.GLFWErrorCallback.<init>(GLFWErrorCallback.java:60)
	at org.lwjgl.glfw.GLFWErrorCallback$2.<init>(GLFWErrorCallback.java:122)
	at org.lwjgl.glfw.GLFWErrorCallback.createThrow(GLFWErrorCallback.java:122)
	at cz.risa.lwjglengine.engine.LWJGLApplication.init(LWJGLApplication.java:68)
	at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:140)
	at cz.risa.testproject.Main.main(Main.java:37)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1CFC0000
	at org.lwjgl.system.Callback.create(Callback.java:133)
	at org.lwjgl.system.CallbackI.address(CallbackI.java:34)
	at org.lwjgl.system.MemoryUtil.memAddressSafe(MemoryUtil.java:727)
	at org.lwjgl.glfw.GLFW.glfwSetCursorPosCallback(GLFW.java:3704)
	at cz.risa.lwjglengine.engine.MouseInput.init(MouseInput.java:32)
	at cz.risa.lwjglengine.engine.LWJGLApplication.init(LWJGLApplication.java:97)
	at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:140)
	at cz.risa.testproject.Main.main(Main.java:37)
Error 00000500 after convex fill

And my Engine Classs
public  class LWJGLApplication {
 private final String title;
 private int width;
 private int height;
 private boolean fullscreen;
 private boolean resizable;
 private boolean antialiasing;
 private long handle;
 private Vector4f clearColor;
 private final ArrayList<ApplicationObject> objects = new ArrayList<>();
 private final Camera camera = new Camera();
 private  Shader shader;
 private  IGameState state;
 private WindowSizeCallback sizeCallback = new WindowSizeCallback();
 private final Transformation transformation = new Transformation();
 private final MouseInput mouseInput = new MouseInput();
 private final KeyboardInput keyboardInput = new KeyboardInput();
 private boolean cullFace;
 private int ups = 0;
 private int fps = 0;
 private Canvas canvas;
 private static GLFWErrorCallback err;
 private GLFWImage.Buffer icons =  null;
 public LWJGLApplication(IGameState state,Properties prop){
      this.state = state;
     this.title = prop.getProperty("title","Game");
     this.width = Integer.parseInt(prop.getProperty("width","500"));
     this.height = Integer.parseInt(prop.getProperty("height","500"));
     this.fullscreen = Boolean.parseBoolean(prop.getProperty("fullscreen","false"));
     this.resizable = Boolean.parseBoolean(prop.getProperty("resizable","true"));
     String str = prop.getProperty("clearColor","0;0;0;0");
     String[]arr = str.split(";");
     this.clearColor = new Vector4f(Float.parseFloat(arr[0]),Float.parseFloat(arr[1]),Float.parseFloat(arr[2]),Float.parseFloat(arr[3]));
     this.antialiasing = Boolean.parseBoolean(prop.getProperty("antialiasing","true"));
     this.cullFace = Boolean.parseBoolean(prop.getProperty("cullFace","true"));
 }
 private void init() throws GLException, ClassNotFoundException, IOException{
     err = GLFWErrorCallback.createThrow();
     if(!GLFW.glfwInit()){
         throw new GLException("cannot initialize GLFW");
     }
     long monitor = MemoryUtil.NULL;
     if(fullscreen){
         monitor = GLFW.glfwGetPrimaryMonitor();
     }
     GLFW.glfwDefaultWindowHints();
     GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR,3);
     GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR,2);
     GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE,GLFW.GLFW_OPENGL_CORE_PROFILE);
     GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT,GLFW.GLFW_TRUE);
     GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE,Utils.parseBoolean(resizable));
     if(antialiasing){
         GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES,4);
     }
     handle = GLFW.glfwCreateWindow(width,height,title,monitor,MemoryUtil.NULL);
     GLFW.glfwSetWindowSizeCallback(handle,sizeCallback);
     if(icons != null){
         GLFW.glfwSetWindowIcon(handle, icons);
     }
     GLFW.glfwMakeContextCurrent(handle);
     GL.createCapabilities();
     GL11.glEnable(GL11.GL_DEPTH_TEST);
     GL11.glEnable(GL11.GL_STENCIL_TEST);
     GL11.glClearColor(clearColor.x,clearColor.y,clearColor.z,clearColor.w);
     canvas = new Canvas(antialiasing,width,height);
     shader = new Shader(Utils.loadResource("/shader/vertex.vs"),Utils.loadResource("/shader/fragment.fs"));
     mouseInput.init(handle);
     keyboardInput.init(handle);
     state.init(this);
 }
 private void destroy(){
     for(ApplicationObject obj:objects){
         obj.destroy();
     }
     state.destroy();
     shader.destroy();
     canvas.destroy();
     icons.free();
     sizeCallback.free();
     Callbacks.glfwFreeCallbacks(handle);
     GLFW.glfwDestroyWindow(handle);
 }
 private void update(){
     GLFW.glfwPollEvents();
     for(ApplicationObject object:objects){
         object.update();
     }
     mouseInput.update();
     canvas.update();
     state.update(mouseInput, keyboardInput,camera,this);
 }
 private void render() throws GLException{
     GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
     GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
     GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
    shader.bind();
    shader.setUniform("projectionMatrix",transformation.getViewMatrix(camera,width,height));
    shader.setUniform("texture_sampler",0);
    for(ApplicationObject obj:objects){
        shader.setUniform("modelMatrix",transformation.getModelMatrix(obj));
        obj.render();
    }
    state.render();
    shader.unbind();
    canvas.draw();
    GLFW.glfwSwapBuffers(handle);
 }
 public void start() throws ClassNotFoundException, IOException{
   try{
     init();
     long lastTime = System.nanoTime();
     double delta = 0.0;
     double ns = 1000000000.0 / 60;
     long timer = System.currentTimeMillis(); 
     while(!GLFW.glfwWindowShouldClose(handle)){
         long now = System.nanoTime();
         delta += (now - lastTime) / ns;
	 lastTime = now;
	if (delta >= 1.0) {
		update();
	        ups++;
		delta--;
         }
         update();
         render();
         fps++;
         if (System.currentTimeMillis() - timer > 1000) {
		timer += 1000;
		ups = 0;
		fps = 0;
	}
     }
     destroy();
   }catch(GLException ex){
       ex.printStackTrace();
   }
 }
 public static void terminateGLFW(){
     err.free();
     GLFW.glfwTerminate();
 }
 public void setState(IGameState state) throws IOException, ClassNotFoundException{
     this.state = state;
     objects.clear();
     this.state.init(this);
 }
 public ArrayList<ApplicationObject> getObjects(){
     return objects;
 }
 public void setDepthTest(boolean depthTest){
     if(depthTest){
         GL11.glEnable(GL11.GL_DEPTH_TEST);
     }else{
         GL11.glDisable(GL11.GL_DEPTH_TEST);
     }
 }
 public Vector4f getClearColor(){
     return clearColor;
 }
 public void setClearColor(Vector4f color){
     this.clearColor = color;
 }
 public boolean isAntialising(){
     return antialiasing;
 }
 public int getWidth(){
     return width;
 }
 public int getHeight(){
     return height;
 }
 public int getFPS(){
     return fps;
 }
 public int getUPS(){
     return ups;
 }
 public void setIcon(InputStream icon) throws IOException{
     GLFWImage image = GLFWImage.malloc();
     PNGDecoder decoder = new PNGDecoder(icon);
     ByteBuffer buffer = BufferUtils.createByteBuffer(decoder.getWidth() * decoder.getHeight() * 4);
     decoder.decode(buffer,decoder.getWidth() * 4, PNGDecoder.Format.RGB);
     buffer.flip();
     image.set(decoder.getWidth(),decoder.getHeight(), buffer);
     icons = GLFWImage.malloc(1);
     icons.put(0,image);
     image.free();
 }
 public Canvas getCanvas(){
     return canvas;
 }
 private class WindowSizeCallback extends GLFWWindowSizeCallback{
        @Override
        public void invoke(long window, int width, int height) {
            LWJGLApplication.this.width = width;
             LWJGLApplication.this.height = height;
             LWJGLApplication.this.canvas.resize(width, height);
             GL11.glViewport(0,0, width,height);
        }
 }
}

So for example in static Method terminateGLFW im freeing the GLFWErrorCallback but the log says that im not freeing it.

spasi

There's another problem in the above stacktrace, the DebugAllocator is throwing an exception because a struct is being freed that was not allocated with the default MemoryUtil allocator:

QuoteException in thread "main" java.lang.IllegalStateException: The memory address specified is not being tracked
    at org.lwjgl.system.MemoryManage$DebugAllocator.untrack(MemoryManage.java:192)
    at org.lwjgl.system.MemoryManage$DebugAllocator.free(MemoryManage.java:153)
    at org.lwjgl.system.MemoryUtil.nmemFree(MemoryUtil.java:254)
    at org.lwjgl.system.Struct.free(Struct.java:47)
    at cz.risa.lwjglengine.engine.object2d.Painter.destroy(Painter.java:63)
    at cz.risa.lwjglengine.engine.object2d.Canvas.destroy(Canvas.java:39)
    at cz.risa.lwjglengine.engine.LWJGLApplication.destroy(LWJGLApplication.java:107)
    at cz.risa.lwjglengine.engine.LWJGLApplication.start(LWJGLApplication.java:163)

After this exception your program terminates early and doesn't have a chance to do proper cleanup. The debug allocator doesn't know this and reports any live allocations at that point as leaks.

Risa123

Painter class
public class Painter {
 private  ByteBuffer fbuffer;
 private final long vg;
 private NVGColor vgColor = null;
 private int width;
 private int height;
 public Painter(long vg,int width,int height) throws IOException, GLException{
     this.vg = vg;
     vgColor = NVGColor.create();
     this.width = width;
     this.height = height;
     setFont("/fonts/OpenSans-Bold.ttf");
 }
 public final void setFont(String resource) throws IOException, GLException{
     fbuffer = Utils.ioResourceToByteBuffer(resource,150 * 1024);
     int err = NanoVG.nvgCreateFontMem(vg,"BOLD", fbuffer,0);
     if(err == -1){
         throw new GLException("cannot create font");
     }
 }
 public void begin(){
     NanoVG.nvgBeginFrame(vg, width, height,1);
 }
 public void end(){
     NanoVG.nvgEndFrame(vg);
     GL11.glEnable(GL11.GL_DEPTH_TEST);
     GL11.glEnable(GL11.GL_STENCIL_TEST);
 }
 public void resize(int width,int height){
     this.width = width;
     this.height = height;
 }
 public void drawRect(Vector4f color,float x,float y,float width,float height){
     rgba(color);
     NanoVG.nvgBeginPath(vg);
     NanoVG.nvgRect(vg, x, y,width,height);
     NanoVG.nvgFillColor(vg,vgColor);
     NanoVG.nvgFill(vg);
 }
 private void rgba(Vector4f color){
     vgColor.r(color.x / 255);
     vgColor.g(color.y / 255);
     vgColor.b(color.z / 255);
     vgColor.a(color.w / 255);
 }
 public void destroy(){
     vgColor.free();
 }
}

Utils class
public class Utils {
 public static String loadResource(String fileName) throws ClassNotFoundException,IOException{
        String result;
        try (InputStream in = Class.forName(Utils.class.getName()).getResourceAsStream(fileName);
             Scanner scanner = new Scanner(in, "UTF-8")) {
            result = scanner.useDelimiter("\\A").next();
        }
        return result;
    }
    public static int parseBoolean(boolean b){
        if(b){
            return 1;
        }
        return 0;
    }
    public static ArrayList<String> readAllLines(String fileName) throws ClassNotFoundException, IOException {
        ArrayList<String> list = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(Class.forName(Utils.class.getName()).getResourceAsStream(fileName)))) {
            String line;
            while ((line = br.readLine()) != null) {
                list.add(line);
            }
        }
        return list;
    }
 @SuppressWarnings("empty-statement")
    public static ByteBuffer ioResourceToByteBuffer(String resource, int bufferSize) throws IOException {
       ByteBuffer buffer;

        Path path = Paths.get(resource);
        if (Files.isReadable(path)) {
            try (SeekableByteChannel fc = Files.newByteChannel(path)) {
                buffer = BufferUtils.createByteBuffer((int) fc.size() + 1);
                while (fc.read(buffer) != -1) ;
            }
        } else {
            try (
                    InputStream source = Utils.class.getResourceAsStream(resource);
                    ReadableByteChannel rbc = Channels.newChannel(source)) {
                buffer = BufferUtils.createByteBuffer(bufferSize);

                while (true) {
                    int bytes = rbc.read(buffer);
                    if (bytes == -1) {
                        break;
                    }
                    if (buffer.remaining() == 0) {
                        buffer = resizeBuffer(buffer, buffer.capacity() * 2);
                    }
                }
            }
        }

        buffer.flip();
        return buffer;
    }
       private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
        ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
        buffer.flip();
        newBuffer.put(buffer);
        return newBuffer;
    }
}

The util class is from gitbook called 3D game development with lwjgl 3. When i was trying replace BufferUtils with MemoryUtil i was getting some errors.
Unfortunately i doesnt remember what errors...

spasi

Quote from: Risa123 on April 01, 2018, 20:26:10
// in the constructor
vgColor = NVGColor.create();
// ...
public void destroy(){
    vgColor.free();
}

Calling .create() returns a struct instance backed by memory allocated with BufferUtils.createByteBuffer. This memory is managed by the JVM, it will be cleaned up automatically via the GC. It is not tracked in the debug allocator. The fix is to either change the .create() call to .calloc(), or remove the .free() call from the destroy method.

Read the Memory FAQ and Memory management in LWJGL 3 for more information.

Risa123

When i changed it to calloc i get access violation. When i remove free i get acces violation.

spasi

Quote from: Risa123 on April 02, 2018, 07:34:47When i changed it to calloc i get access violation. When i remove free i get acces violation.

I'm fairly sure the crash is caused by something else in your code. It will be hard to guess what it is without access to the entire source code or an MCVE. Could you attach the JVM crash log in a reply please?

Other things you could try:

1. GLFWErrorCallback.createThrow() creates but does not register the callback. You need to pass the returned instance to glfwSetErrorCallback().

2. Register an OpenGL error callback with:

// before glfwCreateWindow()
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
 
// ... 
 
// after GL.createCapabilities()
GLUtil.setupDebugMessageCallback();


3. Try running your application with the LWJGLX/debug agent attached.

Risa123

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fef2cb6f60, pid=9520, tid=0x0000000000002730
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b15) (build 1.8.0_112-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [lwjgl.dll+0x16f60]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Risa123\Documents\NetBeansProjects\TestProject\hs_err_pid9520.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

It wil be hard to give you full source code because the project is fairly large but i will try.

spasi

The useful information is in the hs_err_pid9520.log file, could you attach that please? (click on "Attachments and other options" -> "Attach" -> "Choose File")

Quote from: Risa123 on April 02, 2018, 08:11:41It wil be hard to give you full source code because the project is fairly large but i will try.

A minimal sample that reproduces the crash is enough. Preferably a single class that contains all the code, without external resources.

Risa123

I realized that i forget to GLFW.glfwSetErrorCallback. When i enable gl debug im also getting some invalid enum messages. Which are probably caused by NanoVG because im using GL_STATIC_DRAW correctly but i cannot put a crash log ther is a limit for post lenght.

Risa123

Crash log I because a can attach files i will give you full source code just give me some time.

Risa123

lwjgl log
[LWJGL] Version: 3.1.6 build 14
[LWJGL] 	 OS: Windows 7 v6.1
[LWJGL] 	JRE: 1.8.0_112 amd64
[LWJGL] 	JVM: Java HotSpot(TM) 64-Bit Server VM v25.112-b15 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL] 	Found at: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl.dll
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] MemoryUtil allocator: DebugAllocator
[LWJGL] Loading library: glfw
[LWJGL] 	Found at: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\glfw.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\glfw.dll
[LWJGL] Loading library (system): lwjgl_opengl
[LWJGL] 	Found at: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl_opengl.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl_opengl.dll
[LWJGL] Loading library: opengl32
[LWJGL] 	opengl32.dll not found in org.lwjgl.librarypath=C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14
[LWJGL] 	Loaded from system paths
[LWJGL] [GL] GL_ARB_shader_subroutine was reported as available but an entry point is missing.
[LWJGL] [GL] Using KHR_debug for error logging.
[LWJGL] Loading library (system): lwjgl_nanovg
[LWJGL] 	Found at: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl_nanovg.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\Risa123\AppData\Local\Temp\lwjglRisa123\3.1.6-build-14\lwjgl_nanovg.dll
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 3 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 5 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x500
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_ENUM error generated. <usage> enum is invalid; expected GL_STREAM_DRAW, GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_READ, GL_STATIC_COPY, etc. (2 others).
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 6 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x500
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_ENUM error generated. GL_HALF_FLOAT_OES <type> requires extension ARB_ES2_compatibility.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 4 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 7 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 9 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x500
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_ENUM error generated. <usage> enum is invalid; expected GL_STREAM_DRAW, GL_STATIC_DRAW, GL_DYNAMIC_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_READ, GL_STATIC_COPY, etc. (2 others).
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 10 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x500
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_ENUM error generated. GL_HALF_FLOAT_OES <type> requires extension ARB_ES2_compatibility.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 8 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER_EXT, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER (0), and GL_UNIFORM_BUFFER_EXT, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 2 (bound to GL_UNIFORM_BUFFER (0), and GL_UNIFORM_BUFFER_EXT, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Based on the usage hint and actual usage, buffer object 1 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STREAM_DRAW) will be configured as STREAM.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 1 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 1 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STREAM_DRAW) will use VIDEO memory as the source for buffer object operations.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fedf766f60, pid=7316, tid=0x00000000000024b0
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b15) (build 1.8.0_112-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [lwjgl.dll+0x16f60]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Risa123\Documents\NetBeansProjects\TestProject\hs_err_pid7316.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Error 00000500 after convex fill

and source code of my engine. The game itself is just using it.

spasi

This is what I was looking for in the crash dump:

QuoteJava frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.lwjgl.system.dyncall.DynCallback.ndcbGetUserData(J)J+0
j  org.lwjgl.system.dyncall.DynCallback.dcbGetUserData(J)J+12
org.lwjgl.system.Callback.free(J)V+1
j  org.lwjgl.glfw.Callbacks.glfwFreeCallbacks(J)V+158
j  cz.risa.lwjglengine.engine.LWJGLApplication.destroy()V+82
j  cz.risa.lwjglengine.engine.LWJGLApplication.start()V+126
j  cz.risa.testproject.Main.main([Ljava/lang/String;)V+104
v  ~StubRoutines::call_stub

I believe this happens because you free the window size callback explicitly before calling glfwFreeCallbacks:

sizeCallback.free();
Callbacks.glfwFreeCallbacks(handle);


The callback is freed, but you never call glfwSetWindowSizeCallback(window, null). So glfwFreeCallbacks sees that there's still a callback registered and tries to free it. Double-free == crash.

Risa123

I finnaly source code i m new to this website so..