Reputation: 1184
Hey guys. Im trying to render two methods shown below. RenderA() is using VBOs and RenderB() isnt. Im getting an EXC_BAD_ACCESS error when it reaches glDrawArrays() in RenderB().
RenderB() works fine though if i dont create and use any VBOs, ie when i comment out CreateVBOs() and RenderA().
Render() { CreateVBOs(); //glGenBuffers,glBindBuffer,glBufferData etc RenderA(); RenderB(); } RenderA(){ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo->indexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vbo->vertexBuffer); glVertexPointer(3, GL_FLOAT, sizeof(Vertex), 0); glColorPointer(4, GL_FLOAT, sizeof(Vertex), colorOffset); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glDrawElements(GL_TRIANGLES,vbo->indexCount, GL_UNSIGNED_SHORT, bodyOffset); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } RenderB(){ static GLfloat vertices[] = {1.0,1.0,1.0,2.0,1.0,1.0}; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); glDrawArrays(GL_POINTS, 0, 2); glDisableClientState(GL_VERTEX_ARRAY); }
Figured it out. Apparently you have to make sure you unbind the buffer if it was binded before in order to render without vbo.
My CreateVBOs() function binded but did not unbind the buffer so thats what created bad access when RenderB() was trying to use glDrawArrays. Unbinding the buffer is just binding it to 0 like so:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Upvotes: 1
Views: 1941
Reputation: 15109
Try binding GL_ELEMENT_ARRAY_BUFFER and GL_ARRAY_BUFFER to zero before doing your non-VBO draw calls.
Add the following lines of code to the end of your VBO draw calls (RenderA):
glBindBuffer(GL_ElEMENT_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
Upvotes: 9