0

I made a small game in iOS where VBO, IBO, and VAO are created on stage whenever a new model is loaded. When the model is no longer necessary, those buffers are freed.

The buffer creation and destruction is always done at the beginning of the rendering loop (I have a single thread, with frame skipping in the game loop).

I used to use only VBO and VAO and it never crashed before, but when I added index buffer objects, IBOs, I suddenly started getting these crashes.

If I don't free the buffers, it doesn't crash, so I guess the model is still being rendered and erasing the buffer makes it crash? But how can that be if I have a single thread? Btw, I do not erase the data, though. All the vertices and indices are static.

This is the code where I free the buffers, which is called when there are no references left of a particular model:

void ResourceModel::DeleteBuffers(uint16_t modelId)
{
    glDeleteBuffers(1, &m_buffer[modelId]);
    glDeleteBuffers(1, &m_bufferIBO[modelId]);
    glDeleteVertexArraysOES(1, &m_geomVAOs[modelId]);
    glDeleteVertexArraysOES(1, &m_primVAOs[modelId]);
}
endavid
  • 1,781
  • 17
  • 42
  • 1
    Why do you have 2 VAOs for your model? VAOs store the current binding for anything bound to the point: `GL_ELEMENT_ARRAY_BUFFER`. When you delete a buffer it is automatically unbound from anything it is currently bound to (as long as it is in an active context / container object). If you have an IBO bound to a VAO and that VAO is not currently bound, this does not happen. You should delete the VAOs first, though I do not know if that will fix your problem. – Andon M. Coleman Jan 27 '14 at 00:49
  • I changed the order, thanks :) But the thing I just realize it is also crashing before I delete any models... It just takes a bit more to crash v_v -- Btw, I have 2 VAOs, one for each shader. One shader has texture coordinates attribute, but the other hasn't (a geometry pass to render depth early) – endavid Jan 27 '14 at 08:49

0 Answers0