# Exception thrown at 0x00000000 in opengl

**URL:** https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559
**Category:** support
**Created:** [May 12, 2020, 5:23pm UTC](https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559 "2020-05-12T17:23:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![grant\_creamer](https://avatars.discourse-cdn.com/v4/letter/g/51bf81/32.png) [@grant\_creamer](https://discourse.glfw.org/u/grant_creamer)
#### Post date: [May 12, 2020, 5:23pm UTC](https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559/1 "2020-05-12T17:23:49Z")

</div>

hey very new to OpenGL just started watching a video tutorial and I’m getting this error Exception thrown at 0x00000000 in opengl.exe: 0xC0000005: Access violation executing location 0x00000000. occurred it happens on the first glCreateShader

```cpp
#include <iostream>

#define GLEW_STATIC
#include <GL/glew.h>

#include <GLFW/glfw3.h>

const GLchar* vertexShaderSource = "#version 330 core\n"
"layout ( location = 0 ) in vec3 position;\n"
"void main( )\n"
"{\n"
"gl_Position = vec4( position.x, position.y, position.z, 1.0 );\n"
"}\n";

const GLchar* fragmentShaderSource = "#version 330 core\n"
"out vec4 color;\n"
"void main( )\n"
"{\n"
"color = vec4( 1.0f, 0.5f, 0.2f, 1.0f );\n"
"}\n";

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    GLenum err = glewInit();

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
    glCompileShader(vertexShader);

    GLint success;
    GLchar infoLog[512];

    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);

    if (!success)
    {
        glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
        std::cout << "error (vertex)\n" << infoLog << std::endl;
    }

    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fragmentShader, 1, &fragmentShaderSource, NULL);
    glCompileShader(fragmentShader);

    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);

    if (!success) 
    {
        glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
        std::cout << "error (fragment)\n" << infoLog << std::endl;
    }

    GLuint shaderProgram = glCreateProgram();
    glAttachShader(shaderProgram, vertexShader);
    glAttachShader(shaderProgram, fragmentShader);
    glLinkProgram(shaderProgram);

    glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);

    if (!success)
    {
        glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
        std::cout << "error (program linking failed)\n" << infoLog << std::endl;
    }

    glDeleteShader(vertexShader);
    glDeleteShader(fragmentShader);

    GLfloat vertices[] =
    {
        -0.5f, -0.5f, 0.0f, //bottem left
        0.5f, -0.5f, 0.0f, //bottem right
        0.0f, 0.5f, 0.0f
    };
    GLuint VBO, VAO;
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);

    glBindVertexArray(VAO);
    
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
    glEnableVertexAttribArray(0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(0);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        glUseProgram(shaderProgram);
        glBindVertexArray(VAO);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glBindVertexArray(0);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glDeleteVertexArrays(1, &VAO);
    glDeleteBuffers(1, &VBO);

    glfwTerminate();
    return 0;
}

```

---

<div class="post-metadata">

### Author: ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)
#### Post date: [May 12, 2020, 5:48pm UTC](https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559/2 "2020-05-12T17:48:16Z")

</div>

My guess would be that the function `glCreateShader` is `NULL`, i.e. GLEW was unable to load the extension. Have you checked that your driver supports this OpenGL feature (OpenGL 2.0 or the extension)?

---

<div class="post-metadata">

### Author: ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)
#### Post date: [May 12, 2020, 5:57pm UTC](https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559/3 "2020-05-12T17:57:55Z")

</div>

You can ask GLFW to ensure the OpenGL context is version 3.3 (based on 330 in the shaders) or later by setting window hints between init and window creation:

```c
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

```

Then if version 3.3 is unavailable, `glfwCreateWindow` will fail.

---

<div class="post-metadata">

### Author: ![mmozeiko](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/mmozeiko/32/29_2.png) [@mmozeiko](https://discourse.glfw.org/u/mmozeiko)
#### Post date: [May 12, 2020, 7:16pm UTC](https://discourse.glfw.org/t/exception-thrown-at-0x00000000-in-opengl/1559/4 "2020-05-12T19:16:09Z")

</div>

The problem is that GLEW is initialized before OpenGL context is created and made current.  
You should call `glewInit()` after `glfwMakeContextCurrent()` function.
