title: glDeleteBuffers crashes during destructor call
body: <p>Hi I am using VBO to load image texture and then draw it in C++. VBO id generate and bind and draw occurs here</p>
  
  <pre><code>void ViewManager::render(){
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_TEXTURE_2D);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  if(decompressTileImage-&gt;tileTexure == 0)
      {
          loadTexture(decompressTileImage);
          glGenBuffers(1,&amp;decompressTileImage-&gt;VBOId);
          glBindBuffer(GL_ARRAY_BUFFER,decompressTileImage-&gt;VBOId);
          glBufferData(GL_ARRAY_BUFFER,sizeof(*(this-&gt;tileCoordList))+sizeof(*(this-&gt;tileTextureCoordList)),0,GL_STATIC_DRAW);
          glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(*(this-&gt;tileCoordList)),this-&gt;tileCoordList);
          glBufferSubData(GL_ARRAY_BUFFER,sizeof(*(this-&gt;tileCoordList)),sizeof(*(this-&gt;tileTextureCoordList)),this-&gt;tileTextureCoordList);
  
      }
      else
      {
          glBindBuffer(GL_ARRAY_BUFFER,decompressTileImage-&gt;VBOId);
          glBindTexture(GL_TEXTURE_2D, decompressTileImage-&gt;tileTexure);
      }
  
      glColor4f(1.0f, 1.0f, 1.0f, textureAlpha);
  
      if(textureAlpha &lt; 1.0)
      {
          textureAlpha = textureAlpha + .03;
          this-&gt;tiledMapView-&gt;renderNow();
      }
  
  glTexCoordPointer(3, GL_FLOAT, 0, (void*)sizeof(*(this-&gt;tileCoordList)));
  glVertexPointer(3, GL_FLOAT, 0, 0);
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  glBindBuffer(GL_ARRAY_BUFFER,0);
  glDisable(GL_BLEND);
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  glDisable(GL_TEXTURE_2D);
  }
  </code></pre>
  
  <p>This function is in a class named <code>MapTile</code>. <code>MapTile</code> is created 35 times for 35 images downloaded from the internet. And then a thread calls this method 35 times for 35 <code>MapTile</code> object and keeps doing it. That is why I first check if the method is called for the first time so that I can load data and generate VBO id only once for each <code>MapTile</code> object. I check this with <code>if(decompressTileImage-&gt;tileTexure == 0)</code> this line. and then each time I just bind the vbo id to draw. No need to load the data again.</p>
  
  <p>Here <code>decompressTileImage</code> is a <code>TextureImageInfo</code> class. The implementation is</p>
  
  <pre><code>#include "TextureImageInfo.h"
  TextureImageInfo::TextureImageInfo(unsigned char * image,GLuint format,int texWidth,int texHeight,int imageWidth,int imageHeight,float tex_x,float tex_y)
  {
  // TODO Auto-generated constructor stub
  this-&gt;format = format;
  this-&gt;image = image;
  this-&gt;imageHeight = imageHeight;
  this-&gt;imageWidth = imageWidth;
  this-&gt;texHeight = texHeight;
  this-&gt;texWidth = texWidth;
  this-&gt;tileTexure = 0;
  this-&gt;VBOId = 0;
  this-&gt;time = 0;
  
  }
  
  TextureImageInfo::~TextureImageInfo()
  {
  if(VBOId!=0)
      glDeleteBuffers(1,&amp;VBOId);
  }
  </code></pre>
  
  <p>It draws and does everything fine but crashes when I try to clean up the memory in the destructor of <code>TextureImageInfo</code> class which is given here. I don't understand why. I checked to see if the VBOId is generated and loaded in the memory with the if condition in the destructor too. </p>