So I am using a VAO to store pointers from a VBO. I wanted to test what happens when I delete my data buffers (vbo, ibo, etc.) before binding the VAO and calling a draw. Since VAOs store pointers to the data in the corresponding data buffers, I expected the renderer to crash. However, everything keeps working. How is this possible? I am using a WebGL 2.0 context. The documentation states that VAOs are implemented according to OpenGL documentation. Does this has to do with how JavaScript works with objects? Maybe my vbo gets cached somewhere (unknowingly) before I call a deleteBuffer on it. Is this possible? What is happening here?
1 Answers
If a buffer object is tried to be deleted by gl.DeleteBuffers
, then the buffer object is not deleted, if it attached to a vertex array object, which is unbound. In this case the name of the object becomes invalid and it is marked unused:
gl.bindVertexArray( vao );
gl.bindBuffer( gl.ARRAY_BUFFER, vbo );
gl.vertexAttribPointer( ... );
.....
gl.bindVertexArray( 0 );
gl.deleteBuffers( 1, vbo );
But if the vertex array object is bound, then the buffer object is detached and deleted:
gl.bindVertexArray( vao );
gl.bindBuffer( gl.ARRAY_BUFFER, vbo );
gl.vertexAttribPointer( ... );
.....
gl.deleteBuffers( 1, vbo );
gl.bindVertexArray( 0 );
See OpenGL ES Specification 3.2 - 5.1.3 Deleted Object and Object Name Lifetimes, page 45:
When a buffer, texture, transform feedback or renderbuffer object is successfully deleted, it is unbound from any bind points it is bound to in the current context, and detached from any attachments of container objects that are bound to the current context ....
Attachments to unbound container objects, such as deletion of a buffer attached to a vertex array object which is not bound to the context, are not affected and continue to act as references on the deleted object ....
When a buffer, query, renderbuffer, sampler, sync, or texture object is deleted, its name immediately becomes invalid (e.g. is marked unused), but the underlying object will not be deleted until it is no longer in use.

- 202,892
- 27
- 131
- 174
-
Also FYI, object deletion behavior in OpenGL ES is an under-tested part of most drivers. WebGL is supposed to do better and for shaders/programs extensive testing was done for the behavior of deleted shaders and programs. For VAOs it's also supposed to be tested but for WebGL1 it was not tested .. we forgot. For WebGL2 it is tested but Chrome doesn't yet pass [the test](https://www.khronos.org/registry/webgl/sdk/tests/conformance2/vertex_arrays/vertex-array-object.html). Here's the [bug](https://bugs.chromium.org/p/chromium/issues/detail?id=739604) tracking the issue. – gman Nov 14 '17 at 18:26
-
2@gman Oh, I didn't read the WebGL tag, I only read the question, my fault. I changed the code and refere to OpenGL ES now. – Rabbid76 Nov 14 '17 at 18:41
-
sorry for not making that clear... god dammit, i'm using a webgl 2.0 context however i'm testing in chrome. thanks for the input. – SuperTasche Nov 14 '17 at 20:36