Page 1 of 1

detect device closing

Posted: Wed Aug 18, 2021 2:15 pm
by Seven
How can I detect the device closing in response to the WM_QUIT message?

using this code as my main run() loop I have two different scenarios.
If I use set the application mode to IGE_MODE_QUIT to exit the program all works well,
however, if I use the window close button (X) to close the app I get an exception thrown indicating a memory leak.
it is related to me having my own IGE_GUI_Desktop class that handles the gui for me and I need to clean it up prior to the device closing.

question :
how can I detect the WM_QUIT windows message or the postquitmessage() and react to it prior to the device closing?

Code: Select all

		// while everything is valid
		while (getDevice() && getMode() != IGE_MODE_QUIT && getDevice()->run())
		{
			::QueryPerformanceCounter(&end);
			float et = static_cast<float>(end.QuadPart - start.QuadPart) / frequency.QuadPart;
			start = end;

			IGE_PROFILE(getProfiler().stop(EP_APP_TIME_UPDATED);)
			IGE_PROFILE(getProfiler().start(EP_APP_TIME_UPDATED);)

			// call the frame functions
			getEngine()->beginScene(et);
			preFrame(et);
			frame(et);
			postFrame(et);
			getEngine()->endScene(et);


Re: detect device closing

Posted: Thu Aug 19, 2021 9:17 am
by CuteAlien
getDevice()->run() returns false if it's called after it got a WM_QUIT. I don't see rest of your code so I don't know why your cleanup doesn't run.

Edit: You can also always call PeekMessag with PM_NOREMOVE as last parameter to check for WM_QUIT. But you shouldn't have to usually (and that only works on Windows)

Edit: Be aware that there is sometimes (at least in Irrlicht example running on Windows) another option - closing the console window. Which kinda kills the application as well and you don't even get a WM_QUIT. But it's something you can probably ignore and just release without console window (it's main use is to help debugging on Windows).