title: Random crash when calling glDrawArrays
body: <p>I am making an iOS app which can render big number of textures which I stream from disk on the fly. I use a NSCache for LRU cache of textures. There is one screen with a 3D model and one screen with a full screen detail of a texture where this texture can be changed with swiping. Kind of a very simple carousel. The app never takes more then 250MiB of RAM on 1GiB devices, the textures' cache works good.</p>
  
  <p>For the fullscreen view I have a cache of VBOs based on the screen resolution and texture resolution (different texture coordinates). I never delete these VBOs and always check if the VBO is OK (<code>glIsBuffer()</code>). The screens are separate UIViewControllers and I use the same EAGLContext in both of them, no context sharing. This is OK as it is on the same thread.</p>
  
  <p>All this is Open GL ES 2.0 and everything works good. I can switch between the 3D/2D screens, change the textures. The textures are created/deleted on the fly as needed based on the available memory.</p>
  
  <p>BUT sometimes I get a random crash when rendering a full screen quad when calling:</p>
  
  <pre><code>glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  </code></pre>
  
  <p>This can happen when I receive a lot of memory warnings in a row. Sometimes I can get hundreds of memory warnings in few seconds and the app works OK but sometimes it will crash while swiping to new full screen texture quad. This happens even for textures that were already rendered in full screen. It never crashes on the 3D model which uses the same textures.</p>
  
  <p>The crash report is always on the <code>glDrawArrays</code> call (in my code) with a <code>EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000018</code> exception. The last call in a stack trace is always <code>gleRunVertexSubmitARM</code>. This happens on various iPads and iPhones.</p>
  
  <p>It looks like a system memory pressure corrupts some GL memory but I do not know when, where and why.</p>
  
  <p>I have also tried switching from VBO to the old way of having vertex data on the heap, where I first check if the vertex data is not <code>NULL</code> before calling <code>glDrawArrays</code>. The result is the same, random crashes in low memory situations.</p>
  
  <p>Any ideas what could be wrong? The address <code>0x00000018</code> in the <code>EXC_BAD_ACCESS</code> is really bad but I do not know whose address it should be. Could a de-allocated texture or shader cause a <code>EXC_BAD_ACCESS</code> in <code>glDrawArrays</code>?</p>