c++ - CreateRenderWindow() crashed when specify a Qt Window in Ogre -


my app divided 2 modules, 1 game world driven ogre, while gui module implemented using qt.

on app startup create qapplication instance , blank qwindow, put qwindow widget. code this:

```

qapplication qapp(argc, argv); // class gameworld_widget subclass of qwindow 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(); 

```

then create thread create , initilize ogre module elsewhere , pass 'mainthread' control qt.

```

// 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 qt 

```

in ogre module, code this:

```

ogre::namevaluepairlist params; params["externalwindowhandle"] = ogre::stringconverter::tostring(reinterpret_cast<size_t>(hwnd)); ogre::renderwindow *mwindow; try { mwindow = root.createrenderwindow("samplebrowser", 800, 600, false, &params); } 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 } 

```

here question comes. when running

```

/* comment goes here */ mwindow = root.createrenderwindow("samplebrowser", 800, 600, false, &params); 

```

my app crashed, i can't catch exception. enter image description here (i'm chinese language chinese...) progress bar's content 'ogre2.exe has stopped working... windows finding problem' system windows 10, ide visual studio 2015.and ogre version 1.8, qt 5.7.0. choosen ogre render system opengl

qt not allow gui rendering out of main thread. make sure problem.

see: http://doc.qt.io/qt-5/thread-basics.html


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -