[BUG] binding/unbinding vertex array objects might not update StateTracker

Started by jon291, November 20, 2010, 04:04:10

Previous topic - Next topic

jon291

I'm not familiar enough with LWJGL to confirm this, but the behavior I'm getting is very consistent with the stored element array buffer within StateTracker not being updated when binding/unbinding vertex array objects.

Consequently, if you unbind the element array buffer then bind a vertex array object that has an element array buffer associated with it, StateTracker will incorrectly think that no element array buffer is bound and throw an exception ("Cannot use offsets when Element Array Buffer Object is disabled") when calling glDrawElements.  Conversely, if you bind an element array buffer and then bind a vertex array object that has no element array buffer associated with it, StateTracker will incorrectly think that there is an element array buffer bound and allow the program to continue such that a fatal error with the java runtime environment occurs.

spasi

Hey jon291,

Thanks for reporting this and for the useful explanation, this is indeed an LWJGL bug. I'll try to get it fixed asap.

spasi

I've just committed a fix for this, could you please test the next nightly build (from here) and let me know if everything works as expected?

Matthias

Hello Spasi,

it seems you have disabled tracking of Buffer objects passed to GL11.gl*Pointer. If the user app does not hold strong references to these then they can get GCed and cause a crash. One such case could be:
static FloatBuffer wrap(float[] arr) {
    FloatBuffer buf = BufferUtils.createFloatBuffer(arr.length);
    buf.put(arr).flip();
    return buf;
}
....
GL11.glVertexPointer(3, 0, wrap(vertices));
GL11.glColorPointer(4, 0, wrap(colors));
GL11.glTexCoordPointer(2, 0, wrap(texcoords));
GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, vertices.length/3);


this should either be documented as invalid use case or the Buffer objects need to be tracked.

Ciao
Matthias

spasi

Thanks Matthias, good point. That change has been reverted now.