[osg-users] Qt and OpenThreads

12 views
Skip to first unread message

Max Sergeev

unread,
Sep 14, 2012, 5:59:15 AM9/14/12
to osg-...@lists.openscenegraph.org
Hello!

I'm stuck on one problem.

There is kind of big project, and I need to make Qt interface on it. What I try to do is make a camera for Qt-interface element. The problem comes with using OpenThreads: I'm trying to run OSG rendering inside new thread, yielding to rendering of Qt element, like in osgQtBrowser example.
First, I create class to handle thread creating:

Code:

class ViewerFrameThread : public OpenThreads::Thread
{
public:

ViewerFrameThread(osgViewer::ViewerBase* viewerBase, bool doQApplicationExit):
_viewerBase(viewerBase),
_doQApplicationExit(doQApplicationExit) {}

~ViewerFrameThread()
{
cancel();
while(isRunning())
{
OpenThreads::Thread::YieldCurrentThread();
}
}

int cancel()
{
_viewerBase->setDone(true);
return 0;
}

void run()
{
int result = _viewerBase->run();

if (_doQApplicationExit) QApplication::exit(result);
}

osg::ref_ptr<osgViewer::ViewerBase> _viewerBase;
bool _doQApplicationExit;
};




Then I try to run my viewer using it:


Code:

ViewerFrameThread frameThread(m_viewer.getViewerBase());
frameThread.startThread();
return QApplication::exec();




And here comes problem: if I use "frameThread.startThread()" like in example, my project gives me access violation, like every try in new place. Otherwise, if I use "frameThread.run()", everything runs OK but Qt button isnt getting rendered (just a white block in the corner of the screen)

I've tried to make a simply application with just model and Qt-button, and everything works fine with ".startThread()", as button doesnt get rendered with ".run()" same as in my big project. Could not find any documentation of OpenThreads. :(

So the question is, like: is it possible to render Qt thingy with ".run()", or what can possibly cause Access Violation with ".startThread()"?

I'm sorry if the explanation wasnt very clear, though hopefully someone can help :)
Thanks in advance!

Cheers,
Max

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50049#50049





_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Nico Kruithof

unread,
Sep 17, 2012, 4:23:38 AM9/17/12
to osg-...@lists.openscenegraph.org
Hi,

OpenGL rendering with Qt is kind of tricky. Qt wants to render from the main thread, while OSG performs much better with threading enabled. We have a working application with OSG 3.0.1, but it doesn't work anymore with OSG 3.1.2. I still need to investigate that. Qt also has improved OpenGL rendering from a different thread in Qt 4.8, so that might be worth investigating as well.

I did a google search on the topic a while ago and collected usefull information:

Bests,
Nico

--
Nico Kruithof

Max Sergeev

unread,
Sep 19, 2012, 5:52:00 AM9/19/12
to osg-...@lists.openscenegraph.org
Thanks, Nico, very interesting info, I'll read that through. Was not my case, though:
Can't believe how dumb my mistake actually was was: mixing release OSG libraries with debug Qt libraries. Never mix debug with release, thats what I've learned :)

Thanks to all who wanted/tried to help.

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50187#50187
Reply all
Reply to author
Forward
0 new messages