title: glGetAttribLocation/glGetUniformLocation returns 0, causing EXC_BAD_ACCESS on glDrawArrays call (iOS)
body: <p>I am creating a simple OpenGL ES 2.0 application for iOS, and whenever I call glDrawArrays. I found that this was occurring when I had previously called glEnableVertexAttribArray for my two attributes (position and color), and then found that glGetAttribLocation was returning 1 for position, and 0 for color, and then also found that glGetUniformLocation was returning 0 for my MVP matrix. I am not sure if 0 is a valid value, or why glEnableVertexAttribArray appears to be causing EXC_BAD_ACCESS when glDrawArrays is called. </p>
  
  <p>Here is my code:</p>
  
  <p>compileShaders function:</p>
  
  <pre><code>-(void)compileShaders {
  GLuint vertShader = [self compileShader:@"Shader" ofType:GL_VERTEX_SHADER];
  GLuint fragShader = [self compileShader:@"Shader" ofType:GL_FRAGMENT_SHADER];
  
  GLuint program = glCreateProgram();
  glAttachShader(program, vertShader);
  glAttachShader(program, fragShader);
  glLinkProgram(program);
  
  GLint success;
  glGetProgramiv(program, GL_LINK_STATUS, &amp;success);
  if (success == GL_FALSE) {
      GLchar messages[256];
      glGetProgramInfoLog(program, sizeof(messages), 0, &amp;messages[0]);
      NSLog(@"%@", [NSString stringWithUTF8String:messages]);
      exit(1);
  }
  
  glUseProgram(program);
  
  _positionSlot = glGetAttribLocation(program, "position");
  _colorSlot = glGetAttribLocation(program, "color"); //Returns 0
  _mvpSlot = glGetUniformLocation(program, "MVP"); //Returns 0
  
  if (!_positionSlot || !_colorSlot || !_mvpSlot) {
      NSLog(@"Failed to retrieve the locations of the shader variables:\n Position:%i\n Color:%i\n MVP:%i", _positionSlot, _colorSlot, _mvpSlot); //Prints out the values of 1, 0, 0
  }
  
  glEnableVertexAttribArray(_positionSlot);
  glEnableVertexAttribArray(_colorSlot);
  </code></pre>
  
  <p>My render function:</p>
  
  <pre><code>-(void)render:(CADisplayLink *)displayLink {
  glClearColor(0.5, 0.5, 0.5, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);
  
  GLfloat mvp[16] = {
      1.0f, 0.0f, 0.0f, 0.0f,
      0.0f, 1.0f, 0.0f, 0.0f,
      0.0f, 0.0f, 1.0f, 0.0f,
      0.0f, 0.0f, 0.0f, 1.0f,
  };
  
  glUniformMatrix4fv(_mvpSlot, 1, 0, mvp);
  
  glViewport(0, 0, width, height);
  
  glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, 0, vertices);
  glVertexAttribPointer(_colorSlot, 4, GL_UNSIGNED_BYTE, GL_FALSE, 0, colors);
  
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  
  [_context presentRenderbuffer:GL_RENDERBUFFER];
  }
  </code></pre>
  
  <p>And my vertex shader:</p>
  
  <pre><code>attribute vec4 position;
  attribute vec4 color;
  
  uniform mat4 MVP;
  
  varying vec4 v_color;
  
  void main(void) {
      gl_Position = MVP * position;
      v_color = color;
  }
  </code></pre>