【发布时间】:2016-07-04 16:23:50
【问题描述】:
我的应用分为两个模块,一个是Ogre驱动的游戏世界,一个是QT实现的GUI模块。
在应用启动时,我只需创建一个 QApplication 实例和一个空白 QWindow,然后将 QWindow 放入一个 Widget。代码如下所示:
```
QApplication qapp(argc, argv);
// The class gameworld_widget is just a subclass of QWindow with no other content
ui::gameworld_widget *mainWnd = new ui::gameworld_widget;
QWidget mainWndContainer;
mainWndContainer.setObjectName("OGRE222");
mainWndContainer.resize(800, 600);
mainWndContainer.createWindowContainer(mainWnd);
mainWndContainer.show();
```
然后我创建另一个线程来在别处创建和初始化 Ogre 模块,最终我将“主线程”控件传递给 Qt。
```
// Get HWND of gameworld_widget in 'main thread'
auto hMainWnd = reinterpret_cast<HWND>(mainWnd->winId());
std::thread gameWorldThread([hMainWnd]() {
try {
game_world gameWorld(hMainWnd); // see below
}
catch (game_world_exception &ex) {
std::cout << "GameWorldException occurs\n";
return;
}
});
gameWorldThread.detach(); // detach Ogre thread
return qapp.exec(); // pass control to Qt
```
在 Ogre 模块中,我的代码如下所示:
```
Ogre::NameValuePairList params;
params["externalWindowHandle"] = Ogre::StringConverter::toString(reinterpret_cast<size_t>(hwnd));
Ogre::RenderWindow *mWindow;
try
{
mWindow = root.createRenderWindow("SampleBrowser", 800, 600, false, ¶ms);
}
catch (Ogre::Exception ex)
{
std::cout << "Ogre exception occur:" << typeid(ex).name() << ex.what() << "\n";
throw game_world_exception();
}
catch (...)
{
throw game_world_exception(); // comment goes here
}
```
问题来了。运行时
```
/* comment goes here */
mWindow = root.createRenderWindow("SampleBrowser", 800, 600, false, ¶ms);
```
我的应用程序崩溃了,我什至无法捕捉到异常。 (我是中国人,所以语言是中文……)进度条的内容是“Ogre2.exe 已停止工作……Windows 正在寻找问题” 我的系统是Windows 10,IDE是visual studio 2015。Ogre是1.8版本,Qt是5.7.0。选择的 Ogre 渲染系统是 OpenGL
【问题讨论】: