title: glDrawElements EXC_BAD_ACCESS using VBO's
body: <p>i'm having this issue with VBO's that I don't really understand. My problem is solved by accidentally changing the last parameter in the glVertexAttribPointer method call. So, I'm looking for an answer as to <strong>WHY</strong> this is suddenly working or why my previous code isn't working anymore. (just to get a better understanding on opengl)</p>
  
  <p><strong>Struct:</strong></p>
  
  <pre><code>typedef struct 
  {
      float position[3];
      float color[4];
  } Vertex;
  </code></pre>
  
  <p><strong>Without VBOs:</strong></p>
  
  <pre><code>// Get pointers to the data
  GLsizei stride = sizeof(Vertex);
  const GLvoid *pCoords = &amp;squareVertices[0].position[0];
  const GLvoid *pColors = &amp;squareVertices[0].color[0];
  
  // Setup pointers to positions and colors
  glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, pCoords);
  glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, pColors);
  
  // Draw
  glDrawArrays(GL_TRIANGLES, 0, sizeof(squareVertices) / sizeof(Vertex));
  </code></pre>
  
  <p><strong>With VBOs (this gives me an EXC_BAD_ACCESS)</strong></p>
  
  <pre><code>// Stide
  GLsizei stride = sizeof(Vertex);
  
  // Setup pointers to positions and colors
  glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, 0);
  glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, (GLvoid*) (sizeof(float) * 3));
  
  // Draw
  glDrawElements(GL_TRIANGLES, sizeof(squareIndices) / sizeof(squareIndices[0]), GL_UNSIGNED_BYTE, 0);
  </code></pre>
  
  <p>So, the only thing that actually differs is the <code>glVertexAttribPointer</code> call which had a pointer to the data and now has fixed numbers. Can anyone elaborate on this? Thanks in advance.</p>