Title: GLEW _First was nullptr
Tags: c++;glfw;glew
Question: So I have been working on a game through C++ with GLFW and GLEW and everything was going fine until I implemented GLEW then I get an error that I have never encountered before and I don't have the foggiest on what to do, I have googled it and done some research but to no avail. I have noticed that in the stack frame section it says something to do with this line of code in my main.cpp

```st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << glGetString(GL_VERSION) << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
```

Also it says something to do with memory. I'll leave the rest of my code down below and if there's any info you need just ask and I will try my best to provide it

So I just discovered if i take out 

```st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << glGetString(GL_VERSION) << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
```

then it works however the window isn't created. 

Where do I go from here?
Any idea?

```   #include "src\graphics\window.h"
int main() {
    using namespace benji;
    using namespace graphics;

    Window window("Benji Engine", 1280, 720);
    glClearColor(0.2f, 0.3f, 0.8f, 1.0f);
    st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << glGetString(GL_VERSION) << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;``

    while (!window.closed()) {
        st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << window.getWidth() << ", " << window.getHeight() << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
        window.clear();
        glBegin(GL_TRIANGLES);
        glVertex2f(-0.5f, -0.5f);
        glVertex2f(0.0f, 0.5f);
        glVertex2f(0.5f, -0.5f);
        glEnd();
        window.update();
    }

    return 0;
}
```

main.h

``` #pragma once
    class main
    {
    public:
        main();
        ~main();
    };
```

window.cpp

```#include "window.h"

namespace benji { namespace graphics {


void windowResize(GLFWwindow *window, int width, int height);

Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16Window(const char *title, int width, int height) {
    m_Title = title;
    m_Width = width;
    m_Height = height;
    if (!init()) {
        glfwTerminate();
    }

}

Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16~Window() {
    glfwTerminate();

}

bool Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16init() {
    if (!glfwInit()) {
        st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << "Failed to initialize GLFW!" << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
        return false;
    }

    m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
    if (!m_Window) {
        st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << "Failed to create GLFW window!" << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
        return false;
    }
    glfwMakeContextCurrent(m_Window);
    glfwSetWindowSizeCallback(m_Window, windowResize);

    if (glewInit != GLEW_OK) {
        st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << "GLEW FAILED!" << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
        return false;
    }
    return true;


}

void Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16lear() const {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}

void Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16update(){
    glfwPollEvents();
    glfwSwapBuffers(m_Window);


}

    bool Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16losed() const {
    return glfwWindowShouldClose(m_Window) == 1;
}

    void windowResize(GLFWwindow *window, int width, int height) {
        glViewport(0, 0, width, height);
    }
}}
```

window.h

``` #pragma once
    #include <iostream&gt;
    #include <GL\glew.h&gt;
    #include <GLFW\glfw3.h&gt;

namespace benji {
    namespace graphics {
        class Window {
        private:
            const char *m_Title;
            int m_Width, m_Height;
            GLFWwindow *m_Window;
            bool m_Closed;

        public:
            Window(const char *title, int width, int height);
            ~Window();
            bool closed() const;
            void update();
            void clear() const;

             int getWidth() const {
                return m_Width;

            }
             int getHeight() const { return m_Height; }
        private:
            bool init();

        };
}

}
```

Comment: What is the full error? And do you have a debug callstack or any other information?

Comment: If `glGetString` is indeed crashing, it is because your OpenGL has not been properly initialized. Are you getting any error outputs during your `Window181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16init`? This is also supported by the fact that when you remove the call to `glGetString` it does not crash, but no window is opened. See  also "[Why Could glGetString(GL_VERSION) Be Causing a Seg Fault?](http://stackoverflow.com/questions/6288759/why-could-glgetstringgl-version-be-causing-a-seg-fault)"

Comment: The only other error I can see is Exception thrown: read access violation.
_First was nullptr.

Comment: I have been following a tutorial to initialize OpenGL as it's the first time that I have done it and well it seems to be right to me,,, so im not sure.


Here is another answer: In Window.cpp:

```if (glewInit != GLEW_OK) {
    st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16cout << "GLEW FAILED!" << st181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16endl;
    return false;
}
```

```glewInit()``` is a function, not a variable. You need to call it as a function. I'm surprised this even compiled. 

All other OpenGL functions that come from after version 1.1 will throw errors to the effect of ```ACCESS_VIOLATION READING ADDRESS 0x00000000``` or some similar error, because if ```glewInit()``` is not properly called, none of the function macros provided by GLEW will point to valid function pointers.

Comment for this answer: `I'm surprised this even compiled`, so am I if this wasn't just an error in copying the code over to the question. But good catch, I managed to look right past it multiple times.
Comment for this answer: @ssell I stopped using GLEW a while ago (switched to glBinding) and can't remember if GLEW makes everything decay to function pointers, or just the `gl*` functions themselves. If it does it for everything, that would at least explain why the program compiles (but doesn't run correctly).
Comment for this answer: @RyanMidgley I'm not going to make recommendations on that front. I personally like the interface for glBinding more than I like the interface for GLEW, but not everyone is going to feel the same way.
Comment for this answer: So would you recommend not using GLEW?
Comment for this answer: Just gonna let you know how I fixed it, I forgot the parenthesis after glewInit. Something really insignificant but that's the issue haha

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:02/23/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++><glfw><glew>', 'Title': 'GLEW _First was nullptr', 'ViewCount': 154, 'id': 42425176, 'user_AboutMe': None, 'user_AccountId': 10212065.0, 'user_DisplayName': 'Ryan Midgley', 'user_Reputation': 15.0, 'user_Views': 9.0, 'user_id': 7538856.0}}