Searching about VAOs and VBOs I read here and here that I can optionally unbind them to avoid accidental modification so I gave it a try. The problem is that unbinding the VBO causes an access violation when calling glDrawElements and I don't understand why am I getting this behavior.

int main(int argc, char *argv[]) {
    if (!glfwInit()) {
        return -1;

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", nullptr, nullptr);
    glewExperimental = GL_TRUE;

    if (glewInit() != GLEW_OK) {
        return -1;

    GLfloat vertices[] = {
        -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, // Top-left
        0.5f, 0.5f, 0.0f, 1.0f, 0.0f, // Top-right
        0.5f, -0.5f, 0.0f, 0.0f, 1.0f, // Bottom-right
        -0.5f, -0.5f, 1.0f, 1.0f, 1.0f  // Bottom-left

    // Create Vertex Array Object
    GLuint vao;
    glGenVertexArrays(1, &vao);

    //Vertex Buffer Object
    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    // Index Buffer Object
    GLuint elements[] = {
        0, 1, 2,
        2, 3, 0

    GLuint ibo;
    glGenBuffers(1, &ibo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

    (...) // Shader-related stuff

    // Specify the layout of the vertex data
    GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
    glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

    GLint colAttrib = glGetAttribLocation(shaderProgram, "color");
    glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    while (!glfwWindowShouldClose(window)) {
        glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);    

        if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
            glfwSetWindowShouldClose(window, GL_TRUE);


    // Prepare to close the application
    glDeleteBuffers(1, &vbo);
    glDeleteBuffers(1, &vao);
    glDeleteBuffers(1, &eab);

    return 0;

I'm getting the following error and it happens only when I unbind the VBO. Unbinding the VAO and the IBO doesn't throw any exception.

Unhandled exception at 0x0282D434 (ig4icd32.dll) in main.exe: 0xC0000005: Access violation reading location 0x00000000.

Is there a problem with the way I did the unbinding?

  • \$\begingroup\$ How do you create GL context? Which version of OpenGL and which profile (core or compatibility) this context supports? When OpenGL context is being created? \$\endgroup\$
    – Shot
    Commented Jun 22, 2016 at 8:42

1 Answer 1


Before glfwCreateWindow() call these functions:


And after glfwMakeContextCurrent(window) call:

printf("OpenGL version: %s\n", glGetString(GL_VERSION)); 
  • \$\begingroup\$ I tried calling both the glfwWindowHint() statements and the printf() but glGetString(GL_VERSION) printed <null>. Without the glfw hints, it printed "OpenGL version: 2.1.0 - Build" which probably means I don't have support for OpenGL's 3.3 version, right? Could this be the problem here? \$\endgroup\$ Commented Jun 22, 2016 at 9:43
  • \$\begingroup\$ Yup, since VAOs are core functionality since OpenGL 3.0. Up to this version of OpenGL you have to use ARB_vertex_array_object extension (if your GPU supports it). What GPU you have installed in your PC/laptop? \$\endgroup\$
    – Shot
    Commented Jun 22, 2016 at 9:54
  • \$\begingroup\$ It's a Mobile Intel(R) 4 Series Express Chipset Family and, if I searched the right place, it does not support the ARB extension. I'll test it out later on a newer GPU to see if it works. \$\endgroup\$ Commented Jun 22, 2016 at 10:05
  • \$\begingroup\$ @JeanCatanho Someone comments the linked article stating it is outdated and the driver supports more extensions. Can't verify the claim myself. You should query the extensions list and check what is supported in runtime. Good luck \$\endgroup\$
    – Andreas
    Commented Jun 22, 2016 at 16:32
  • \$\begingroup\$ @Andreas thanks for the suggestion, I queried it here and it looks like it's supported and I tested the same code on a GeForce GTX 750 Ti and it worked like a charm, the problem really was due to OpenGL's version. Thank you both. \$\endgroup\$ Commented Jun 23, 2016 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .