base.exitFunc vs base.win.setCloseRequestEvent()

The distinction between the two is not clear:

https://docs.panda3d.org/1.10/python/_modules/direct/showbase/ShowBase#exitfunc

https://docs.panda3d.org/1.10/python/reference/panda3d.core.GraphicsWindow#panda3d.core.GraphicsWindow.setCloseRequestEvent

I specifically want to do some cleanup and save current settings before exiting.

The close request event is fired when the user tries to close the window, by clicking the X or pressing Alt+F4 or something like that. If you set this event, then you get an opportunity to intercept this and show a confirmation dialog (“are you sure you want to close?”) instead of the default action of closing the window, after which it’s your responsibility to actually close the window via an API call to honour the user’s request.

The exitFunc is called when the window has been closed, either via user action or via an API call.

If you don’t care about intercepting the user’s close request, you should probably prefer exitFunc.

1 Like

Thank you.

To confirm, unless you want to provide visual feedback to the user, is there much of a difference for saving the current app settings and doing cleanup (a) before or (b) after the window has been closed?

BTW this is quite useful, should probably be in the manual.

Your intuition is as good as mine here. I’d be inclined to do it after, so that the app responds immediately to the user’s request. And that the method gets called if you closed the window programmatically in some other part of your codebase.