OpenGL error: Unhandled exception at 0x02c6ee05

When I try to create some variables (array of GLfloats, not sure about other types), I get this error:

Unhandled exception at 0x02c6ee05 in gltools_4.exe: 0xC0000005: Access violation reading location 0x10624dd3.

Here's the program code:

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
#include <GLTools.h>
#include <GLShaderManager.h>

#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endif

GLBatch triangleBatch;
GLShaderManager shaderManager;

void ChangeSize(int w, int h){
	glViewport(0, 0, w, h);
}

void setupRC(){
	glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

	shaderManager.InitializeStockShaders();

	GLfloat vVerts[] = {-0.5f, 0.0f, 0.0f,
						0.5f, 0.0f, 0.0f,
						0.0f, 0.5f, 0.0f};
	triangleBatch.Begin(GL_TRIANGLES, 3);
	triangleBatch.CopyVertexData3f(vVerts);
	triangleBatch.End();
}

void RenderScene(void){
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	GLfloat vRed[] = {1.0f, 0.0f, 0.0f, 1.0f};
	shaderManager.UseStockShader(GLT_SHADER_IDENTITY);
	triangleBatch.Draw();

	glutSwapBuffers();
}

int main(int argc, char* argv[]){
	gltSetWorkingDirectory(argv[0]);

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Triangle");
	glutReshapeFunc(ChangeSize);
	glutDisplayFunc(RenderScene);

	GLenum err = glewInit();
	if(GLEW_OK != err){
		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
		return 1;
	}

	setupRC();
	glutMainLoop();

	return 0;
}


I have linked to the GLTools library and added gltools.lib and freeglut_static.lib to the project (I have the opengl superbible 5th edition and that's what it said to do, but I still get this error).

Anyone know how to fix it?
Build with debug symbols, run under debugger, identify the line of your code that attempts to use memory that does not belong to you, fix that code.

Example of finding exactly this kind of problem (more commonly known as a segFault) using the gdb debugger: http://www.cplusplus.com/articles/iwTbqMoL/
Last edited on
It's shaderManager.UseStockShader(GLT_SHADER_IDENTITY);, but when you say "fix that code", that's what I'm asking how to do...

Also, it happened before on line 23, but I made a new project and copied and pasted the code into it and it worked then.

Edit: Never mind, I managed to fix it. For some reason it wasn't working because I was trying to debug it :p As soon as I changed Debug to Release, it worked.
Last edited on
Topic archived. No new replies allowed.