Strange Exception Throwing

Somehow the following code throws an exception:

'Exception thrown at 0x00000000 in GL.2.exe: 0xC0000005: Access violation executing location 0x00000000.'

1
2
unsigned int VB, IB;
glGenBuffers(1, &VB); 

Exception thrown on line 2 of the above.

Can't for the life of me understand why this is happening.

Full main() function:

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
int main()
{
	float vertices[]
	=	{
		960.0F, 0.0F,
		960.0F, 270.0F,
		480.0F, 270.0F,
		480.0F, 0.0F
		};

	unsigned short int indices[]
	=	{
		0,1,2,
		2,3,0
		};

	unsigned int VB, IB;
	glGenBuffers(1, &VB);
	glBindBuffer(GL_ARRAY_BUFFER, VB);
	glNamedBufferData(VB, sizeof(vertices),vertices,GL_STATIC_DRAW);

	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);

	glGenBuffers(1, &IB);
	glBindBuffer(GL_ARRAY_BUFFER, IB);
	glNamedBufferData(IB, sizeof(indices), indices, GL_STATIC_DRAW);

	{
		GLFW glfw(960,540);
		ImmediateModeGUI ImGui(glfw.GetWindowID());

		while (!glfw.WindowShouldClose())
		{
			glClearColor(0.0F,  0.0F, 0.0F, 1.0F); // prefix GLCall()
			glClear(GL_COLOR_BUFFER_BIT); // prefix GLCall()
			ImGui.NewFrame();
			ImGui.Begin("Test");
			glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
			ImGui.End();
			ImGui.Render();
			glfw.SwapBuffers();
		}
	}
}

Last edited on
glGenBuffers is a function pointer whose value is nullptr, and you attempted to call it. Most likely there's some initialization step for the library that you didn't perform.

See if this helps: https://stackoverflow.com/questions/14131083/linking-to-opengl-from-a-dll-glew-functions-are-null-when-running?rq=1
Last edited on
[SOLVED] glfwInit() and glewInit() need to be called prior to buffer generation. My fault.
Topic archived. No new replies allowed.