title: 0xC0000005: Access violation executing location 0x00000000. (OpenGL)
body: <p>I have looked at several other questions on stack about this and it mentions de-referencing null pointers but I don't understand if that applies to my code.</p>
  
  <p>The code crashes at line 33 in the World.cpp when trying to generate a VAO:</p>
  
  <pre><code>glGenVertexArrays(1, &amp;vao);
  </code></pre>
  
  <p>giving me the error shown in the title. If I comment out that line the program runs fine.</p>
  
  <p><strong><em>PhaseEngineMain.cpp</em></strong></p>
  
  <pre><code>#include "PhaseEngineMain.h"
  #include "PhaseEngineController.h"
  
  int main(int argc, char *argv[])
  {
      PhaseEngineController engine;
      engine.start();
      return 0;
  }
  </code></pre>
  
  <p><strong><em>PhaseEngineController.h</em></strong></p>
  
  <pre><code>#pragma once
  #include "SDL.h"
  #include "glew.h"
  #include "World.h"
  #include &lt;iostream&gt;
  
  class PhaseEngineController
  {
  public:
      PhaseEngineController();
      ~PhaseEngineController();
  
      void InitialiseEngine();
      void IntitialseOpenGL();
      void InitialiseSDL(Uint32 x, Uint32 y, Uint32 width, Uint32 height, Uint32 flags);
      void InitialiseGLEW();
      void SetClearColour(float r, float g, float b, float a);
      void PrintIntialisationInfo();
      void start();
      void stop();
      void run();
      void UpdateLoop();
      void RenderLoop();
      void SwapBackBuffer();
  
  private:
      SDL_Window* window;
      SDL_GLContext opengl_context;
      World world;
  
      bool running = false;
  };
  </code></pre>
  
  <p><strong><em>PhaseEngineController.cpp</em></strong></p>
  
  <pre><code>#include "PhaseEngineController.h"
  
  
  PhaseEngineController::PhaseEngineController()
  {
      InitialiseEngine();
  
      InitialiseSDL(500, 500, 900, 600, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
      IntitialseOpenGL();
      InitialiseGLEW();
      PrintIntialisationInfo();
      world.addMesh();
  }
  
  
  PhaseEngineController::~PhaseEngineController()
  {
      SDL_GL_DeleteContext(opengl_context);
      SDL_DestroyWindow(window);
      SDL_Quit();
  }
  
  void PhaseEngineController::InitialiseEngine()
  {
      std::cout &lt;&lt; "Intialising...\n" &lt;&lt; std::endl;
  }
  
  void PhaseEngineController::IntitialseOpenGL()
  {
      opengl_context = SDL_GL_CreateContext(window);
      glClearColor(0, 0,0, 1);
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LESS);
      std::cout &lt;&lt; "gl initialised - rendering ready" &lt;&lt; std::endl;
  }
  
  void PhaseEngineController::InitialiseSDL(Uint32 x, Uint32 y, Uint32 w, Uint32 h, Uint32 f)
  {
      int error = SDL_Init(SDL_INIT_EVERYTHING);
      SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
      window = SDL_CreateWindow("Phaze Engine", x, y, w, h, f);
      std::cout &lt;&lt; "SDL initialised - window created" &lt;&lt; std::endl;
  }
  
  void PhaseEngineController::InitialiseGLEW()
  {
      GLenum err = glewInit();
  
      if (GLEW_OK != err)
      {
          /* Problem: glewInit failed, something is seriously wrong. */
          fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
      }
      else
      {
          std::cout &lt;&lt; "GlEW Intialised - library ready" &lt;&lt; std::endl;
      }
  }
  
  void PhaseEngineController::SetClearColour(float r, float g, float b, float a)
  {
      glClearColor(r, g, b, a);
  }
  
  void PhaseEngineController::start()
  {
      if (running) return;
      running = true;
      run();
  }
  
  void PhaseEngineController::stop()
  {
      if (!running) return;
      running = false;
  }
  
  void PhaseEngineController::run()
  {
  
      while (running)
      {
          //std::cout &lt;&lt; "working" &lt;&lt; std::endl;
          RenderLoop();
          //UpdateLoop();
  
      }
  }
  
  void PhaseEngineController::UpdateLoop()
  {
      SDL_Event event;
  
      while (running)
      {
          /* Check for new events */
          while (SDL_PollEvent(&amp;event))
          {
              /* If a quit event has been sent */
              if (event.type == SDL_QUIT)
              {
                  /* Quit the application */
                  running = false;
              }
          }
      }
      world.update();
  }
  
  void PhaseEngineController::RenderLoop()
  {
      world.render();
      SwapBackBuffer();
  }
  
  void PhaseEngineController::SwapBackBuffer()
  {
      SDL_GL_SwapWindow(window);
  }
  
  void PhaseEngineController::PrintIntialisationInfo()
  {
      std::cout &lt;&lt; "\nEngine Initialized...\n" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p><strong><em>World.cpp</em></strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  
  unsigned int vbo = 0;
  unsigned int vao = 0;
  
  float points[] = {
      0.0f, 0.5f, 0.0f,
      0.5f, -0.5f, 0.0f,
      -0.5f, -0.5f, 0.0f
  };
  
  World::World()
  {
      std::cout &lt;&lt; "world created" &lt;&lt; std::endl;
  }
  
  World::~World()
  {
      std::cout &lt;&lt; "world destroyed" &lt;&lt; std::endl;
  }
  
  void World::addMesh()
  {
      glGenBuffers(1, &amp;vbo);
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      glBufferData(GL_ARRAY_BUFFER, 9 * sizeof (float), points, GL_STATIC_DRAW);
      glGenVertexArrays(1, &amp;vao); //// &lt;-- crashes here, this is line 33
  
      std::cout &lt;&lt; "mesh added " &lt;&lt; std::endl;
  }
  
  void World::update() { }
  
  void World::render() { }
  </code></pre>