Systems Shutdown order

(Moving something over from the mailing list to make the discussion public)

So me and Arturo have been hacking a bit on an OpenGL ES 2.0 renderer and I’ve run into a small issue someone here might be able to help with.

Basically I need to control the order at which things are released on shutdown and I can’t quite find where this is done. Or actually just make sure that the renderer is released last.

I have an ofLight in my testApp and when when you exit testApp this is released (although not explicitly by my me), the ofLight as a final call does:

In ofLight.cpp, line 110 in the function static void release(ofLight & light) :
light.setAmbientColor(ofColor(0,0,0,255));

Long story short, this eventually makes it to ofGraphics.cpp that on line 1104 does this:

void _ofLightfv (unsigned int light, unsigned int pname, const float *params){
renderer->_lightfv( light, pname, params );

}

( in this repos https://github.com/andreasmuller/openFrameworks/tree/develop-opengles2 )

At this point renderer has already been released though it seems, and I can’t really find where this is done.
static ofPtr renderer; lives at the top of ofGraphics.cpp, but there is no obvious place I can find where it is set to NULL or something like that.

Pointers welcome!
(see wat I did there?)

[hr]

And Arturos reply:

both the renderer and testApp are static references inside .cpp’s so
they are released automatically when the application ends. The problem
is you don’t know in which order. There should be something in the exit
callback that releases this resources in the correct order. there should
be an ofReleaseRenderer function that gets called after having deleted
the app.

Actually we need to solve the shutdown in general for every class and
system, ie: the shut down functions for the sound player backend right
now have:

//TODO: FIX THIS SHIT!!!
//#warning FIX THIS.
void ofSoundStopAll();

: )

[hr]

This is actually quite important, especially for those of us who embed oF into plugin environments like QC or Unity, where our oF based effects, renderers etc may be instantiated and destroyed multiple times during the host applications life cycle.

Deterministic shut down would be very nice to have.