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.