Jump to content
  • Advertisement
Sign in to follow this  
madmax46

Program crashes in glDrawArrays from segfault over time (using VBO)

This topic is 2782 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

In my application, we are using VBOs for our texture coordinates and vertex coordinates. Multiple images share the same texture VBO and have their own vertex VBO. The application runs fine 99.9% of the time, but after running for hours and hours the program sometimes will crash in glDrawArrays with a segfault. I'm wondering if anyone has experienced this issue or would know why this may happen so I can look into it further in our code. One theory I had was that the VBO was getting swapped off of graphics card memory, but then I would expect to have gotten an error when we try to bind. I've got error checking code after almost every gl call to try and determine if some error is getting thrown that we were missing and we get nothing. It just crashes. At this point I'm thinking it may be a driver bug since I would think that either glDrawArrays will crash always or never due to a segfault. Here is some of the code (btw, we use jogl):



// enable required states
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);

// This is where we share texture coordinates
if (sharedCoords == null) {
sharedCoords = sharedCoordinateMap.get(key, gl);
}

// Check for an error since sharedCoordinateMap will generate the coordinates/VBO id if none exist for the key.
int error = gl.glGetError();
if (error != GL.GL_NO_ERROR) {
// handle the error
glTarget.handleError(error);
// don't draw
draw = false;
}

// if we should draw and we haven't generated our vertex VBO yet...
if (draw && vertexId < 0) {
// our vertex vbo is not created, create and discard verticies
int[] vbos = new int[1];
gl.glGenBuffers(1, vbos, 0);
vertexId = vbos[0];
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexId);
gl.glBufferData(GL.GL_ARRAY_BUFFER,
vertexCoordinates.capacity() * 4,
vertexCoordinates.rewind(), GL.GL_STATIC_DRAW);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
// We can set this to null now so java can garbage collect it since it is on graphics memory now.
vertexCoordinates = null;
}

// Check for error on previous operation
error = gl.glGetError();
if (error != GL.GL_NO_ERROR) {
glTarget.handleError(error);
draw = false;
}

// if we should draw (no previous errors) and we have our texture and vertex VBO ids set, draw
if (draw && sharedCoords.textCoordId > -1 && vertexId > -1) {
// We have both a texture and vertex vbo, paint
// Bind the vertexId and set the pointer.
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexId);
gl.glVertexPointer(2, GL.GL_FLOAT, 0, 0);

// Check for errors...
error = gl.glGetError();
if (error != GL.GL_NO_ERROR) {
glTarget.handleError(error);
draw = false;
}

// Bind the textureid and set the pointer
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, sharedCoords.textCoordId);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);

// again, check for error
error = gl.glGetError();
if (error != GL.GL_NO_ERROR) {
glTarget.handleError(error);
draw = false;
}

// Draw each triangle strip
for (int i = 0; i < key.horizontalDivisions; ++i) {
// Crashes here...
gl.glDrawArrays(GL.GL_TRIANGLE_STRIP,
(i * 2 * key.verticalDivisions),
key.verticalDivisions * 2);
// check for error after each draw....
error = gl.glGetError();
if (error != GL.GL_NO_ERROR) {
glTarget.handleError(error);
draw = false;
}
}

// bind the buffer to 0
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
} else {
shouldDraw = false;
statusHandler.handle(Priority.PROBLEM,
"Error: image mesh was not constructed properly");
}

gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);


Again, all code works 99.9% of the time, just crashes after running for long periods of time like 16-20+ hours.

Thanks

Max

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!