0
$\begingroup$

I have a class that handles loading buffers for a mesh:

class A {
   GLuint vao, vbo, ebo;

   A() {
      glGenVertexArrays(1, &vao);
      glGenBuffers(1, &vbo);
      glGenBuffers(1, &ebo);
        
      LoadBuffers();
      LoadAttributes();
   }

   ~A() {
     DeallocateBuffers();
   }
}

When an object of that class is destructed I would like to free the memory allocated by the buffers. I can't figure out how do this correctly. This is what I tried but it doesn't seem to be correct.

void DeallocateBuffers() {
    glDeleteVertexArrays(1,&vao);
    glDeleteBuffers(1,&ebo);
    glDeleteBuffers(1,&vao);
}
$\endgroup$
3
  • $\begingroup$ Schouldn't you use vbo instead of vao in the second glDeleteBuffers call? $\endgroup$ – wychmaster Nov 22 '20 at 11:17
  • $\begingroup$ @wychmaster Yeah sorry it should be vbo $\endgroup$ – Lenny White Nov 22 '20 at 14:25
  • $\begingroup$ @LennyWhite: "but it doesn't seem to be correct." ... why not? $\endgroup$ – Nicol Bolas Nov 23 '20 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.