1

I caught this exception when running the program:

Exception thrown at 0x0000000000000000 in OpenGL project.exe: 0xC0000005: Access violation executing location 0x0000000000000000.

This is my code below:

#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{
    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window{ glfwCreateWindow(800, 800, "Win", NULL, NULL) };

    if (window == NULL)
    {
        std::cout << "Doesn't work";
        glfwTerminate();
        return -1;
    }

    gladLoadGL();
    glfwMakeContextCurrent(window);

    glViewport(0, 0, 800, 800);

    glClearColor(50.0f, 1.3f, 1.7f, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers(window);

    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

The code stopped working when I tried to add color

This is the link to the tutorial I was using: https://youtu.be/z03LXhRBLGI?list=PLPaoO-vpZnumdcb4tZc4x5Q-v7CkrQ6M-

I have no idea what the exception could be referring to

I tried moving a few things around like putting this block into the while statement

    glViewport(0, 0, 800, 800);

    glClearColor(50.0f, 1.3f, 1.7f, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers(window);
1
  • 0x0000000000000000 is a null pointer. Commented Mar 31, 2024 at 23:39

1 Answer 1

1

The OpenGL Context is required and must be the current Context to load the OpenGL API. Therefore glfwMakeContextCurrent must be called before gladLoadGL (see also glad):

glfwMakeContextCurrent(window);
gladLoadGL();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.