Sign in to follow this  

OpenGL and GLUT memory runtime error

This topic is 2500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;":
[code]


// 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[i] = 0;
pTexCoords[i] = NULL;
}
}

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

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

[code]

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

[/code]


Does anyone have an idea what's causing the problem? It's probably something very simple

Share this post


Link to post
Share on other sites
Well, it's more than likely wholly your part [img]http://public.gamedev.net/public/style_emoticons/default/wink.gif[/img].

What are you getting from glGetError()?

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

How are you initializing temp?

Share this post


Link to post
Share on other sites
I figured out what was going wrong. Temp was going out of scope
Thank you

Share this post


Link to post
Share on other sites

This topic is 2500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this