title: nvoglv32.dll Access violation reading location 0x00000000
body: <p>I've been having a problem lately with openGL. In my program that has worked fine before, I try to draw a group of polygons to the screen but the program throws an error and for the life of me I can't find the cause of it. I've literally changed nothing from my code, it just started throwing errors one day after coming back to it after a month. The error is:</p>
  
  <pre><code>Unhandled exception at 0x69F2883E (nvoglv32.dll) in openGLtest.exe: 
  0xC0000005: Access violation reading location 0x00000000.
  </code></pre>
  
  <p>I have reproduced the error with the code below. Some more strange behavior I've noticed is that if I change the call to glDrawArrays to something like:</p>
  
  <pre><code>glDrawArrays(GL_TRIANGLES, 3, numV);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>glDrawArrays(GL_TRIANGLES, 0, 258);
  </code></pre>
  
  <p>then the program doesn't throw the error though obviously it doesn't render properly, rendering only half of the rectangle, or rendering the rectangle plus some garbage input.</p>
  
  <p>It's very strange, if it renders more than 255 points it works fine but any less and it throws the error.</p>
  
  <pre><code>#include &lt;SDL.h&gt;
  #include &lt;GL/glew.h&gt;
  #include &lt;math.h&gt;
  #include &lt;vector&gt;
  
  struct Vector2f{
  public:
      float x, y;
      Vector2f() {}
      Vector2f(float _x, float _y) { x = _x; y = _y; }
  };
  struct Vector3f {
  public:
      float x, y, z;
      Vector3f() { x = 0.0, y = 0.0, z = 0.0; }
      Vector3f(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
  };
  struct Vertex {
      Vector3f m_pos;
      Vector2f m_tex;
      Vector3f m_normal;
      Vertex() {}
      Vertex(Vector3f pos, Vector2f tex) {
          m_pos = pos;
          m_tex = tex;
          m_normal = Vector3f(0.0f, 0.0f, 0.0f);
      }
      Vertex(Vector3f pos, Vector2f tex, Vector3f norm) {
          m_pos = pos;
          m_tex = tex;
          m_normal = norm;
      }
  };
  
  SDL_Window*         Window_Display  = NULL;
  SDL_GLContext       glcontext;
  GLuint              VBO;
  int                 width           = 800;
  int                 height          = 600;
  float               ratio           = (float)width / (float)height;
  int                 numV;
  std::vector&lt;Vertex&gt; _VBO;
  
  bool initWindow() {
      //draw a square
      _VBO.push_back(Vertex(Vector3f(-0.8f, -0.8f, 0.0f), Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      _VBO.push_back(Vertex(Vector3f(0.8f, -0.8f, 0.0f),  Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      _VBO.push_back(Vertex(Vector3f(0.8f, 0.8f, 0.0f),   Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      _VBO.push_back(Vertex(Vector3f(-0.8f, -0.8f, 0.0f), Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      _VBO.push_back(Vertex(Vector3f(-0.8f, 0.8f, 0.0f),  Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      _VBO.push_back(Vertex(Vector3f(0.8f, 0.8f, 0.0f),   Vector2f(0.0f, 0.0f), Vector3f(0.0f, 0.0f, 0.0f)));
      numV = 6;
  
      if (SDL_Init(SDL_INIT_VIDEO) &lt; 0) return false;
      if ((Window_Display = SDL_CreateWindow("OpenGL Drawing Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL)) == NULL) return false;
  
      glcontext = SDL_GL_CreateContext(Window_Display);
  
      glewInit();
  
      return true;
  }
  
  bool drawScene() {
      glEnableClientState(GL_VERTEX_ARRAY);
  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
      glLoadIdentity(); //Reset the drawing perspective
  
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
      glEnableVertexAttribArray(2);
  
      glGenBuffers(1, &amp;VBO);
      glBindBuffer(GL_ARRAY_BUFFER, VBO);
      glBufferData(GL_ARRAY_BUFFER, numV * sizeof(Vertex), &amp;_VBO[0], GL_STATIC_DRAW);
  
      glBindBuffer(GL_ARRAY_BUFFER, VBO);
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12);
      glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)20);
      glDrawArrays(GL_TRIANGLES, 0, numV);    //Unhandled exception at 0x69F2883E (nvoglv32.dll) in openGLtest.exe: 0xC0000005: Access violation reading location 0x00000000.
  
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);
      glDisableVertexAttribArray(2);
  
      SDL_GL_SwapWindow(Window_Display); //Send the 3D scene to the screen
  
      glDisableClientState(GL_VERTEX_ARRAY);
  
      return true;
  }
  
  int main(int argc, char* args[]) {
      if (initWindow()) {
          while (drawScene()) {}
      }
      return 0;
  }
  </code></pre>