_frstnullptr error with GLEW

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
 
std::cout << glGetString(GL_VERSION) << std::endl;


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

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #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);
	std::cout << glGetString(GL_VERSION) << std::endl;

	while (!window.closed()) {
		std::cout << window.getWidth() << ", " << window.getHeight() << std::endl;
		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
1
2
3
4
5
6
7
8
#pragma once
class main
{
public:
	main();
	~main();
};


window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "window.h"

namespace benji { namespace graphics {
	
	
	void windowResize(GLFWwindow *window, int width, int height);
	
	Window::Window(const char *title, int width, int height) {
		m_Title = title;
		m_Width = width;
		m_Height = height;
		if (!init()) {
			glfwTerminate();
		}

	}

	Window::~Window() {
		glfwTerminate();

	}

	bool Window::init() {
		if (!glfwInit()) {
			std::cout << "Failed to initialize GLFW!" << std::endl;
			return false;
		}
			
		m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
		if (!m_Window) {
			std::cout << "Failed to create GLFW window!" << std::endl;
			return false;
		}
		glfwMakeContextCurrent(m_Window);
		glfwSetWindowSizeCallback(m_Window, windowResize);

		if (glewInit != GLEW_OK) {
			std::cout << "GLEW FAILED!" << std::endl;
			return false;
		}
		return true;


	}

	void Window::clear() const {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	void Window::update(){
		glfwPollEvents();
		glfwSwapBuffers(m_Window);

		
	}

		bool Window::closed() const {
		return glfwWindowShouldClose(m_Window) == 1;
	}

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


window.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <iostream>
#include <GL\glew.h>
#include <GLFW\glfw3.h>

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();

		};
}

}
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
 
std::cout << glGetString(GL_VERSION) << std::endl;


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

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #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);
	std::cout << glGetString(GL_VERSION) << std::endl;

	while (!window.closed()) {
		std::cout << window.getWidth() << ", " << window.getHeight() << std::endl;
		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
1
2
3
4
5
6
7
8
#pragma once
class main
{
public:
	main();
	~main();
};


window.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "window.h"

namespace benji { namespace graphics {
	
	
	void windowResize(GLFWwindow *window, int width, int height);
	
	Window::Window(const char *title, int width, int height) {
		m_Title = title;
		m_Width = width;
		m_Height = height;
		if (!init()) {
			glfwTerminate();
		}

	}

	Window::~Window() {
		glfwTerminate();

	}

	bool Window::init() {
		if (!glfwInit()) {
			std::cout << "Failed to initialize GLFW!" << std::endl;
			return false;
		}
			
		m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
		if (!m_Window) {
			std::cout << "Failed to create GLFW window!" << std::endl;
			return false;
		}
		glfwMakeContextCurrent(m_Window);
		glfwSetWindowSizeCallback(m_Window, windowResize);

		if (glewInit != GLEW_OK) {
			std::cout << "GLEW FAILED!" << std::endl;
			return false;
		}
		return true;


	}

	void Window::clear() const {
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	void Window::update(){
		glfwPollEvents();
		glfwSwapBuffers(m_Window);

		
	}

		bool Window::closed() const {
		return glfwWindowShouldClose(m_Window) == 1;
	}

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


window.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <iostream>
#include <GL\glew.h>
#include <GLFW\glfw3.h>

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();

		};
}

}
Last edited on
So I just discovered if i take out
 
std::cout << glGetString(GL_VERSION) << std::endl;


then it works however the window isn't created.

Where do I go from here?
Any idea?
Topic archived. No new replies allowed.