WM_QUIT was not sent to my app when OS was shutting down.
I found WM_QUERYENDSESSION and WM_ENDSESSION were sent to all the windows instead of WM_QUIT at that time.
Here’s the inserted code in juce_win32_Windowing.cpp:
case WM_QUERYENDSESSION:
if(JUCEApplication::getInstance() != 0)
JUCEApplication::getInstance()->systemRequestedQuit();
return TRUE;
Surely if the user is resorting to the task manager to kill an app, the app should really be taking the hint and just get the hell out of the way! Trying to be clever at that point sounds like a recipe for disaster IMHO.
User Might not intentionally killed the app. He just wanted to kill one app and by mistake i would have killed the other one. So we can give some provision to clean up right!!!
If you close an app via Task Manager, the OS will try to close it normally first. If the app won’t respond to the normal close message, then it is forcibly killed. That is, by definition, an abnormal situation that means your app is already not functioning correctly.
I have been having issues with the WM_QUERYENDSESSION handler. When I end up my user session on windows, the JUCEApplication::shutdown() is called, but it gets killed before completing (and this is very painful to debug since I have to close/reopen the session to trigger this). After some tracing I found that the calls to ::DestroyWindow that are done after WM_QUERYENDSESSION has been received are just killing the application (and they are numerous during the shutdown since I destroy the main application window, the tooltip window etc). I’m pretty sure there is a logical explanation, but I’m far from figuring it !
I ended up toggling a global flag when WM_ENDSESSION is received, and when this flag is toggled, the call to DestroyWindow in destroyWindowCallback() is just skipped. Of course, this is extremely ugly, but at least my shutdown completes…
I think they are called after, because when you call JUCEApplication::systemRequestedQuit it is asynchronous, isn’t it ? Anyway, I also tried to call directly JUCEApplication::getInstance()->shutdown() when receiving the ENDSESSION event, but it did not change anything. However I know almost nothing about windows message queues etc so I really don’t know how all those events are supposed to fire