I'm starting my DirectX 11.1 Metro (without XAML) application as following:
[Platform::MTAThread]
int main(Platform::Array<Platform::String^>^)
{
// Some additional initializations
//...
auto frameworkViewSource = ref new MyFrameworkViewSource();
Windows::ApplicationModel::Core::CoreApplication::Run(frameworkViewSource);
}
Run function is below:
virtual void Run()
{
while(!m_windowClosed)
{
CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
DoWork();
}
}
Then I'm trying to call Quit function (in case user requested exit):
Quit()
{
// Uninit variables
//...
Windows::ApplicationModel::Core::CoreApplication::Exit();
}
But
Windows::ApplicationModel::Core::CoreApplication::Exit();
has no effect. As a result I have crash in DoWork() function because variables were uninitialized but application wasn't exited and while loop is continuing.
Also, in case I call CoreWindow::GetForCurrentThread()->Close() from the Quit function, debugger never hits OnWindowClosed event handler:
m_window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &MyFrameworkView::OnWindowClosed);
void MyFrameworkView::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
{
m_windowClosed = true;
}
The question is: how do I properly quit the game in case I'm planning to have "Quit" item in menu?