Access violation on glCreateShader() despite GLAD initialization?


i'm trying to work with OpenGL, which i did before few times, but now i have problem that when i call glCreateSHader(GL_VERTEX_SHADER) i get error 0xC0000005: Access violation executing location i tried reading multiple articles on Stackoverflow, GLFW sites etc etc but everyone was using glew and i use glad and i couldn't get this to work, here is some code from my Game.cpp file:

int main() {

    DisplayManager display;

    Shader shader;

    display.CreateDisplay(800, 600);

    while (!glfwWindowShouldClose(display.window)) {


        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);




    return 0;


here is CreateDisplay function from DisplayManager.cpp:


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

#ifdef __APPLE__



    DisplayManager::window = glfwCreateWindow(Width, Height, "Thing", NULL, NULL);

    if (window == NULL) {

        std::cout << "Failed to Create Window" << std::endl;


        return -1;



    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {

        std::cout << "Failed to initialize glad" << std::endl;

        return -1;


    glViewport(0, 0, Width, Height);

    glfwSetFramebufferSizeCallback(window, frameBufferSizeCallback);

i've initialized glad after glfwMakeContextCurrent(window); and it's initialized okay, it runs but when i get to Creating Shader i run into multiple that error, here is my code for Shader.cpp (Shader class is not finished yet, there are some stuff that are not finished like actually using the shader etc, so just saying):

#include "Shader.h"

Shader::Shader() {

    string VertexSource = GetSource("src/Shaders/VertexShader.shader");
    //string FragmentSource = GetSource("srd/Shaders/FragmentShader.shader");

    unsigned int VertexID = CompileShader(GL_VERTEX_SHADER, VertexSource);
    //unsigned int FragmentID = CompileShader(GL_FRAGMENT_SHADER, VertexSource);


string Shader::GetSource(const char* path) {

    ifstream file;
    stringstream buffer;

    string source = "";;

    if (file.is_open()) {

        buffer << file.rdbuf();

        source = buffer.str();

    } else {

        cout << "Could not open file: " << path << endl;



    return source;


unsigned int Shader::CompileShader(GLenum Type, string source) {

    int success;
    char infoLog[512];

    unsigned int ID = glCreateShader(GL_VERTEX_SHADER); //I get error on this line

    const GLchar* src = source.c_str();

    glShaderSource(ID, 1, &src, NULL);

    glGetShaderiv(ID, GL_COMPILE_STATUS, &success);

    if (!success) {

        glGetShaderInfoLog(ID, 512, NULL, infoLog);
        cout << "Errorwith loading: " << Type << " infoLog: " << infoLog << endl;


    return ID;


How it's marked in the code, i get error when calling line: unsigned int ID = glCreateShader(GL_VERTEX_SHADER); (also i have the Type hard coded for Vertex Shader for now because i wanted to see if it will change anything, but it didn't) i've red alot of articles on Stackoverflow, if someone needs to know somethign more just tell me in comments

asked on Stack Overflow May 25, 2021 by ChrisHusky • edited May 25, 2021 by ChrisHusky

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0