I am currently trying to learn OpenGL and have run into a problem. It seems like when I try to unbind my Index Buffer, the error "Exception thrown at 0x78787D80 (nvoglv32.dll) in OpenGLCourseApp.exe: 0xC0000005: Access violation reading location 0x00000000." pops up and therefore I can't run my program.
Here is my code for reference:
void CreateTriangle() {
unsigned int indices[] = {
0, 3, 1,
1, 3, 2,
2, 3, 0,
0, 1, 2
};
GLfloat vertices[] = {
-1.0f, -1.0f, 0.0f,
0.0f, -1.0f, 1.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f
};
// Create and Bind VAO
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glGenBuffers(1, &IBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// Create and Bind VBO
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDeleteBuffers(1, &IBO);
glBindVertexArray(0);
}
int main() {
/..
CreateTriangle();
CompileShaders();
// Loop until window is closed
while (!glfwWindowShouldClose(mainWindow)) {
/..
glBindVertexArray(VAO);
// glDrawArrays(GL_TRIANGLES, 0, 3);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
glBindVertexArray(0);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// glDeleteBuffers(1, &IBO);
glUseProgram(0);
glfwSwapBuffers(mainWindow);
}
return 0;
}
So, in int main(), when I try to unbind the index buffer via glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);, it errors out with "Exception thrown at 0x78787D80 (nvoglv32.dll) in OpenGLCourseApp.exe: 0xC0000005: Access violation reading location 0x00000000." I have tried doing glDeleteBuffers(1, &IBO);, but that doesn't seem to work. I've even tried glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, nullptr); and that doesn't work either. It doesn't seem like an NVIDIA Driver from what I've heard, rather something is returning as NULL and the driver doesn't like it maybe?
User contributions licensed under CC BY-SA 3.0