title: Swift: glDrawElements crashing with EXC_BAD_ACCESS code=1
body: <p>I'm learning <strong>OpenGL</strong> on iOS by this <a href="http://www.raywenderlich.com/3664/opengl-tutorial-for-ios-opengl-es-2-0" rel="nofollow">guide</a>, and I want to implement everything on <strong>swift</strong>. So, there is some code were I'm getting crash:</p>
  
  <p>Memory structures:</p>
  
  <pre><code>private struct Vertex {
      var Position: (GLfloat, GLfloat, GLfloat)
      var Color: (GLfloat, GLfloat, GLfloat, GLfloat)
  }
  
  private static var Vertices = [
      Vertex(Position: (1, -1, 0) , Color: (1, 0, 0, 1)),
      Vertex(Position: (1, 1, 0)  , Color: (0, 1, 0, 1)),
      Vertex(Position: (-1, 1, 0) , Color: (0, 0, 1, 1)),
      Vertex(Position: (-1, -1, 0), Color: (0, 0, 0, 1))
  ]
  
  private static var Indices: [GLubyte] = [
      0, 1, 2,
      2, 3, 0
  ]
  </code></pre>
  
  <p>Create vertex buffers:</p>
  
  <pre><code>var vertexBuffer = GLuint()
  glGenBuffers(1, &amp;vertexBuffer)
  glBindBuffer(GLenum(GL_ARRAY_BUFFER), vertexBuffer)
  glBufferData(GLenum(GL_ARRAY_BUFFER), Vertices.size, Vertices, GLenum(GL_STATIC_DRAW))
  
  var indexBuffer = GLuint()
  glGenBuffers(1, &amp;indexBuffer)
  glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), indexBuffer)
  glBufferData(GLenum(GL_ELEMENT_ARRAY_BUFFER), Indices.size, Indices, GLenum(GL_STATIC_DRAW))
  </code></pre>
  
  <p>Setup memory offsets:</p>
  
  <pre><code>var positionPtr = 0
  glVertexAttribPointer(GLuint(positionSlot), 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(strideofValue(Vertex)), &amp;positionPtr)
  var colorPtr = strideof(GLfloat) * 3
  glVertexAttribPointer(GLuint(colorSlot), 4, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(strideofValue(Vertex)), &amp;colorPtr)
  </code></pre>
  
  <p><strong>Crash</strong> (Trying to draw):</p>
  
  <pre><code>var startPtr = 0
  // EXC_BAD_ACCESS code=1 here!
  glDrawElements(GLenum(GL_TRIANGLES), GLsizei(Indices.count / 3), GLenum(GL_UNSIGNED_BYTE), &amp;startPtr)
  </code></pre>
  
  <p>All shaders are compiled without any errors and <code>glClear()</code> draws well, so I suppose my problem is concerned with VBOs.</p>
  
  <p>And here how I calculate size of arrays:</p>
  
  <pre><code>extension Array
  {
      var size: Int {
          get { return self.count * strideof(Element) }
      }
  }
  </code></pre>
  
  <p>UPD: I'm using OpenGLES 2.0.</p>