# glDeleteBuffers causing other objects not to draw

I have few objects in scene and they exist until I turn off the application. Their calls for glDeleteBuffers are in destructor. Since I don't delete anything in the middle of the game everything is fine. But now I created one helper function for drawing lines with following body:

void DrawLine(glm::vec3 p1, glm::vec3 p2, glm::vec4 color)
{
GLuint vao, vbo;

glm::vec3 data[2] = { p1, p2 };

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 2 * sizeof(glm::vec3) * 2, data, GL_STATIC_DRAW);

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);

glEnableVertexAttribArray(0);

glBindVertexArray(vao);

glDrawArrays(GL_LINES, 0, 2);

glDeleteBuffers(1, &vbo);
glDeleteBuffers(1, &vao);
}


But as soon as glDeleteBuffers is called nothing is drawing anymore. If I comment those two lines everything is fine (except a bunch of unreleased object names of course).

Anyone know why is this happening?

• You are using glDeleteBuffers() on a vertex array object, you should use glDeleteVertexArrays(1, &vao); – ashleysmithgpu Jul 3 '14 at 12:42

I am just rehashing what @yuumei said, but since he did not post an awnser:

You are creating the vao object with:

 glGenVertexArrays(1, &vao);


As such you need to delete it with:

glDeleteVertexArrays(1, &vao);


Here is the documentation for glGenVertexArrays.

What happens here is that the value in vao is the same value with some other buffer and as such that buffer is being deleted instead. Next time you try to use that buffer, it will not work, since you deleted it.

• Thanks! That was the problem. Didn't realize there was separate function for deleting vao. – instancedName Jul 3 '14 at 16:39