Sign in to follow this  
ChrisPepper1989

Problems with Ogre Message Pumping

Recommended Posts

Hi Everyone, A friend and I created our own framework to use with Ogre and everthing worked but one small thing, we couldnt alt-tab out of a program or even restore it after going to a break point in the code. I figured that the application was simply not handling windows messages so I did a bit of searching and came across:
Ogre::WindowEventUtilities::messagePump();
//p.s this code is showing in a massive code window, is it showing in a massive window to you?  its enapsulated in the source /source ive tried with lang = "cpp" =S

which seemed to solve the problem, however it came with an unwanted side effect, now when the program ends abruptly, i.e. the program crashes or i press shift->f5 (im using visual studios C++ 2008), the console window won't close with the app window, and it wont let me close it manually or even end its process and worst of all the computer won't shut down, i have to switch it off (which always makes me feel wrong =P). Its not really ideal and i would very much like to solve this, i also tried a manual approach:
MSG msg;
	while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
	{
		if (msg.message == WM_QUIT)
		    this->ShutDown();
		else 
		{
		     TranslateMessage(&msg);
		     DispatchMessage(&msg);
		}
	}

because i assumed it wasnt handling the quit properly but of course if the code ends abruptly it will never call the shutdown... Does anyone have any ideas on how to either solve this problem or an alternate solution to the alt tab/restoring problem? i have considered setting up http://www.gamedev.net/reference/articles/article1249.asp this way but im unsure whether it would really solve the problem, my theory is if the message loop was in a thread it would somehow carry on running and allow window closure but it doesnt seem like a neat solution and it feels like i shouldnt be having this problem anyway. If anyone can offer any advice it would be very appreciated! Thank you for your time, Chris
	void Application::Run()
	{
		while(!mQuitGame)
		{
			//Ogre::WindowEventUtilities::messagePump(); //enables window going in/out of focus (Chris)
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
		{
			MSG msg;
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
			{
				 if (msg.message == WM_QUIT)
					 this->ShutDown();
				 else 
				 {
					 TranslateMessage(&msg);
					 DispatchMessage(&msg);
				 }
			}
		}
#endif


			mTimer->update();

			float dT = mTimer->getDeltaTime();
		
			//Logger::GetInstance()->Log(XF::Utilities::ToString<float>(dT));

			GameComponentMapIt it;

#ifdef X_CONSOLE_POSSIBLE
			if(!mConsoleOnly)
			{
#endif
			mInput->update();
			OnHandleInput(dT, mInput);
#ifdef X_CONSOLE_POSSIBLE
			}
#endif


			for(it = mGameComponents->begin(); it != mGameComponents->end(); ++it)
				(*it).second->HandleInput(dT, mInput);

			OnUpdate(dT);

			for(it = mGameComponents->begin(); it != mGameComponents->end(); ++it)
				(*it).second->Update(dT);

			OnDraw();

			for(it = mGameComponents->begin(); it != mGameComponents->end(); ++it)
				(*it).second->Draw();

#ifdef X_CONSOLE_POSSIBLE
			if(!mConsoleOnly)
#endif
			mOgre->GetRoot()->renderOneFrame();

		}
	}

Share this post


Link to post
Share on other sites
Quote:
Original post by ChrisPepper1989
Hi Everyone,

A friend and I created our own framework to use with Ogre and everthing worked but one small thing, we couldnt alt-tab out of a program or even restore it after going to a break point in the code. I figured that the application was simply not handling windows messages so I did a bit of searching and came across:
*** Source Snippet Removed ***

This is not unexpected: if you're not handling window messages, there's no way your application can handle window state changes (focus changes with ALT+TAB or resizing/positioning with restoring). Note that if you've broken into the debugger however, your code is not running and hence messages aren't getting pumped regardless..

Quote:
which seemed to solve the problem, however it came with an unwanted side effect, now when the program ends abruptly, i.e. the program crashes or i press shift->f5 (im using visual studios C++ 2008), the console window won't close with the app window, and it wont let me close it manually or even end its process and worst of all the computer won't shut down, i have to switch it off (which always makes me feel wrong =P)

Sounds like this problem that has recently been occurring:
Click 1, click 2

Share this post


Link to post
Share on other sites
oh i wasnt expecting that, it does seem like a re-occuring problem with the patch KB977165 which is exeptionally annoying as it means ill get the problem on the machines I use in university still! i might put in a quick define set up so i can disable the message pump on computers that have KB977165.

EDIT - it seems some people are saying removing KB978037 is the fix...i seem to have neither on this machine and from what it seems, this machine is fine! When i test this on the home machine (where i've had problems) i shall post up what worked for me =]

Thank you so much for that i never woul have assumed a bug in visual studios!

[Edited by - ChrisPepper1989 on February 18, 2010 9:51:22 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this