Hello Guest

Memory corruption during glfwTerminate

  • 2 Replies
  • 197 Views
Memory corruption during glfwTerminate
« on: March 17, 2019, 09:33:44 »
Hi all,

I have a problem with a memory corruption during glfwTerminate. When I run this program and press esc to exit I get this:

Renderer.destroy: 1
malloc(): memory corruption

The problem goes away if I don't create and destroy the Buffer object so I guess it has something to do with that. But I can't figure out what's wrong. I'm using lwjgl 3.2.1.1 on Linux

All the code (minimized as much as I could):
https://gist.github.com/McJty/69a7130ce54caf765434c3af865d1b1a

Thanks in advance

*

Offline KaiHH

  • ***
  • 182
Re: Memory corruption during glfwTerminate
« Reply #1 on: March 17, 2019, 09:47:06 »
Look at your Buffer.init() method. You free the verticesBuffer twice by calling memFree(verticesBuffer) twice.
Code: [Select]
    private void init() {
        FloatBuffer verticesBuffer = MemoryUtil.memAllocFloat(vertices.length);
        verticesBuffer.put(vertices).flip();

        vaoId = glGenVertexArrays();
        glBindVertexArray(vaoId);

        vboId = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, vboId);
        glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW);
        memFree(verticesBuffer); // <- FREE HERE!!!

        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);

        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindVertexArray(0);

        if (verticesBuffer != null) { // <- is true
            MemoryUtil.memFree(verticesBuffer); // <- AND HERE!!!
        }
    }

Re: Memory corruption during glfwTerminate
« Reply #2 on: March 17, 2019, 09:49:53 »
Oh thanks. I totally missed that