PDA

View Full Version : Deleting VBO and VAO soon after drawing



pripon
05-26-2014, 12:02 AM
In my render loop, I'm creating a VBO and VAO for some object I'll be drawing. In one particular instance the object will only be temporary (it's the same code for whether it's temporary or not), so drawn after creating those two objects and then deleted soon after (all within the same render loop). I'm wondering what the behaviour is for this kind circumstance? I would've thought the referenced made by the draw call would've kept the objects alive, regardless of if I deleted them myself. But my application doesn't seem to render it correctly when it does this (the object doesn't get drawn at all).

e.g. On the one particular case my render loop looks like this:
enter render loop
do some drawing
{//draw this particular object
create vbo with data for that object
create vao for state that is used to setup when drawing that object
draw object
}
delete object (vao and vbo)
do some drawing
exit render loop

Typically it normally keeps those objects alive for awhile (many render loops), and so this problem isn't apparent.

So is it correct behaviour for OpenGL not to keep those objects alive? And so I have to change it so the object won't be deleted till the next frame, or flushing the commands, etc.

Update: Actually I just tried flushing it (tried finishing too), and still same problem. Only works if I postpone the deletion till the next render loop.

Ilian Dinev
05-26-2014, 04:18 AM
It's not correct behaviour, so I think it's a driver bug :( . If you're using a GeForce, try disabling "multithreaded optimisations" from the nvidia control panel.

When deleting a buffer, it will get unbound only from the currently-bound VAO. I suggest you try first deleting the VAO, then VBO; but this is just a hack.
When deleting a buffer or anything, the GL spec dictates that for external purposes, the object names get instantly deleted, but internally, the data backing them should remain alive until the GPU finishes using it.

pripon
05-26-2014, 07:19 AM
Yeh I thought so (about how deletions are handled). Also deleting the VAO first then the VBO worked, thanks. I guess I'll just have to file a bug report and wait for a proper fix.