OpenGL and GLUT memory runtime error

Started by
1 comment, last by zoner7 13 years, 2 months ago
So I'm writing my first program in OpenGL using GLUT. I'm writing this program while simultaneously reading the OpenGL Superbible 5th edition. After tracing through the source code, I learned that the error occurs in the OpenGL Superbible's source... but I have a feeling it's partially my fault.

Here is the error: "Unhandled exception at 0x00c0ff8b in Primitives.exe: 0xC0000005: Access violation writing location 0x00000004."
The error occurs in this chunk of code inside GLBatch.cpp on the line "nNumVerts = nVerts;":



// Start the primitive batch.
void GLBatch::Begin(GLenum primitive, GLuint nVerts, GLuint nTextureUnits)
{
primitiveType = primitive;
nNumVerts = nVerts;

if(nTextureUnits > 4) // Limit to four texture units
nTextureUnits = 4;

nNumTextureUnits = nTextureUnits;

if(nNumTextureUnits != 0) {
uiTextureCoordArray = new GLuint[nNumTextureUnits];

// An array of pointers to texture coordinate arrays
pTexCoords = new M3DVector2f*[nNumTextureUnits];
for(unsigned int i = 0; i < nNumTextureUnits; i++) {
uiTextureCoordArray = 0;
pTexCoords = NULL;
}
}

// Vertex Array object for this Array
#ifndef OPENGL_ES
glGenVertexArrays(1, &vertexArrayObject);
glBindVertexArray(vertexArrayObject);
#endif
}


Here is my code that calls this GLBatch::Begin():



temp->Begin(GL_TRIANGLES, 3);
temp->CopyVertexData3f(vertices);
temp->End();
batches.push_back(*temp);




Does anyone have an idea what's causing the problem? It's probably something very simple
Advertisement
Well, it's more than likely wholly your part wink.gif.

What are you getting from glGetError()?

[edit] nm, Maybe I should have read that second line there...[/edit]

How are you initializing temp?
I figured out what was going wrong. Temp was going out of scope
Thank you

This topic is closed to new replies.

Advertisement