title: EXC_BAD_ACCESS with glTexImage2D in GLKViewController
body: <p>I have an <code>EXC_BAD_ACCESS</code> at the last line of this code (this code is fired several times per second), but I cannot figure out what is the problem:</p>
  
  <pre><code>[EAGLContext setCurrentContext:_context];
  glActiveTexture(GL_TEXTURE0);
  glPixelStorei(GL_PACK_ALIGNMENT, 1);
  glBindTexture(GL_TEXTURE_2D, _backgroundTexture);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _outputFrame.cols, _outputFrame.rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, _outputFrame.data);
  </code></pre>
  
  <p>When debugging I make sure that the texture is created (the id is > 0), output frame has a valid pointer to the data and is a 4 channel matrix. I am inside the <code>drawRect</code> method of a GLKViewController. I think I should not have to bind the framebuffer as it is one of the things that are automated here. <strong>It doesn't crash at the first frame, but a few dozens frames later.</strong></p>
  
  <p>Can anybody spot the problem?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>It seems it's because of a race condition on <code>_outputFrame</code>, it's being updated while being read by <code>glTexImage2D</code>. I will try to lock it for read, then report back.</p>