Simple request with a nontrivial solution, as usual. Right now, calling exit() on GLFW/SDL2 application just stops executing the main loop, which unconditionally leads to resource cleanup and exiting the program. In particular, the ExitEvent, allowing the exit to be aborted, is not fired here. That means there's no builtin way to request application exit via, say, a button in the application UI and have it behave the same way as if the window close button was clicked.
In case of SDL2, this behavior can be implemented by manually pushing an exit event instead of calling exit(), however that doesn't allow the user to specify the exit code:
In case of GLFW, there unfortunately doesn't seem to be a builtin way, glfwSetWindowShouldClose(window(), true) leads to an unconditional stop of the event loop, with the callback from glfwSetWindowCloseCallback() never entered. Possibly related issue that could allow posting "fake" events to implement this: https://github.com/glfw/glfw/issues/688
Alternatively, this could be implemented outside of SDL/GLFW, simply by firing the ExitEvent if an exit is requested, and then possibly cancelling the exit.
Things to do:
[ ] Document the current behavior, so it's clear exit() sidesteps the ExitEvent
[ ] Implement this for SDL and GLFW, outside of their event loop to have common handling for both
[ ] Having ExitEvent fired from exit() might not make sense in all cases, especially when the app wants to unconditionally exit due to some unrecovarable failure, or from a constructor (or maybe from the constructor it wouldn't trigger the event?), so maybe a new requestExit() API with this behavior might make sense instead?
Simple request with a nontrivial solution, as usual. Right now, calling
exit()
on GLFW/SDL2 application just stops executing the main loop, which unconditionally leads to resource cleanup and exiting the program. In particular, theExitEvent
, allowing the exit to be aborted, is not fired here. That means there's no builtin way to request application exit via, say, a button in the application UI and have it behave the same way as if the window close button was clicked.In case of SDL2, this behavior can be implemented by manually pushing an exit event instead of calling
exit()
, however that doesn't allow the user to specify the exit code:In case of GLFW, there unfortunately doesn't seem to be a builtin way,
glfwSetWindowShouldClose(window(), true)
leads to an unconditional stop of the event loop, with the callback fromglfwSetWindowCloseCallback()
never entered. Possibly related issue that could allow posting "fake" events to implement this: https://github.com/glfw/glfw/issues/688Alternatively, this could be implemented outside of SDL/GLFW, simply by firing the
ExitEvent
if an exit is requested, and then possibly cancelling the exit.Things to do:
exit()
sidesteps theExitEvent
ExitEvent
fired fromexit()
might not make sense in all cases, especially when the app wants to unconditionally exit due to some unrecovarable failure, or from a constructor (or maybe from the constructor it wouldn't trigger the event?), so maybe a newrequestExit()
API with this behavior might make sense instead?exit()
doesn't seem to do an actual quit, just stops event processing: https://gitter.im/mosra/magnum/archives/2022/01/11?at=61dcc94b9b470f38975db494Cc: @jvannugteren @hsdk123