detect device closing

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

detect device closing

Post 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);

CuteAlien
Admin
Posts: 9643
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: detect device closing

Post 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).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply