glBindBuffer() acces violation

closed account (DEhqDjzh)
I got access violation error here is the code:
and The VBO and VAO are in the class called "Graphics" with these functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// main loop
Graphics g;
while (!glfwWindowShouldClose(g.window))
	{

		g.stuptriangle();
	g.render();
	
	
	
	}





 

Render:
1
2
3
4
5
6
7
8
9
10
11
12
 

	// render
	glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glBindVertexArray(VAO);
	glDrawArrays(GL_TRIANGLES, 0, 3);
	glBindVertexArray(0);

	glfwSwapBuffers(window);
	glfwPollEvents();

Setup triangle:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
glGenBuffers(1, &VBO);  
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
	glEnableVertexAttribArray(0);
	
	glGenVertexArrays(1, &VAO);				
	glBindVertexArray(VAO);					
											
	glVertexAttribPointer(
		0,							
		3,							
		GL_FLOAT,					
		GL_FALSE,					
		0,							
		NULL);						

	glEnableVertexAttribArray(0);	
Can you also show the declarations and initializations of VBO and VAO?

And, just to be clear, you're saying the access violation happens inside of the glBindBuffer call (not in a call before or after it)?

Edit:

1. Is this the first gl____ function you call in your program? (If not, what other OpenGL calls do you make before this?) Are you sure you have a valid OpenGL context before you call gl* functions? It looks like your Graphics object is what creates the window, so you should make sure you aren't calling any OpenGL functionality until after the window is properly initialized for OpenGL.

2. Are you using multiple threads?
Last edited on
closed account (DEhqDjzh)
Found the solution!
initglew() must be called before glmakecurrentcontex()
Last edited on
Topic archived. No new replies allowed.