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();
}
}