Hi all,
We're currently creating a new app where we need to be able to create
new views, each of which needs to have a separate graphics context
(because they need to be attached to Qt windows - so each needs to get a
unique window handle).
When adding views, I'm hitting what seems to be a threading issue
(deadlock or something like that). It'll happen after adding 2, 3 or 4
views, not always the same number, but I can rarely get more than 5
total. On the call stack, I can see one thread per context is in
GraphicsWindowWin32::makeCurrentImpl() (this is DrawThreadPerContext, so
that's ok), and a third one is in ViewerBase::renderingTraversals() on a
conditionalWait, and they all seem to be stalled there. I'll copy the
stack traces below.
I've reproduced the problem even without Qt, by modifying osgviewer.cpp,
adding an event handler that just creates a new view, calls
setUpViewInWindow() and sets the scene root on it to the same as the
first view. I've tried surrounding the addView call with stopThreading()
and startThreading(), but it doesn't seem to change anything.
I've attached my modified osgviewer.cpp. If someone's inclined to try it
out, just start it with cow.osg for example, and press 'a' to add a view
(note that the 'a' key will only work on the first window).
Is there anything else I need to be careful of when adding views at run
time? Anything I need to do to make this work?
Thanks in advance,
J-S
Stack traces:
Thread 1
=========================================================================
[EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x84 bytes
[EMAIL PROTECTED]() + 0x12 bytes
ot11-OpenThreadsd.dll!OpenThreads::cooperativeWait(void *
waitHandle=0x00000318, unsigned long timeout=4294967295) Line 55 +
0x10 bytes C++
>
ot11-OpenThreadsd.dll!OpenThreads::Win32ConditionPrivateData::wait(OpenThreads::Mutex
& external_mutex={...}, long timeout_ms=-1) Line 109 + 0x1d bytes C++
ot11-OpenThreadsd.dll!OpenThreads::Condition::wait(OpenThreads::Mutex
* mutex=0x0237c1e4) Line 63 C++
osg50-osgViewerd.dll!OpenThreads::BlockCount::block() Line 133 +
0x17 bytes C++
osg50-osgViewerd.dll!osgViewer::ViewerBase::renderingTraversals()
Line 753 C++
osg50-osgViewerd.dll!osgViewer::ViewerBase::frame(double
simulationTime=1.7976931348623157e+308) Line 608 + 0xf bytes C++
osg50-osgViewerd.dll!osgViewer::ViewerBase::run() Line 580 + 0x1b
bytes C++
osg50-osgViewerd.dll!osgViewer::CompositeViewer::run() Line 219
C++
AddView.exe!main(int argc=2, char * * argv=0x0229c828) Line 177 +
0xe bytes C++
AddView.exe!__tmainCRTStartup() Line 597 + 0x19 bytes C
AddView.exe!mainCRTStartup() Line 414 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 2
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() - 0x51 bytes
[EMAIL PROTECTED]() + 0xd7 bytes
[EMAIL PROTECTED]() + 0x1f bytes
nvoglv32.dll!6970f597()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 3
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x84 bytes
[EMAIL PROTECTED]() + 0x12 bytes
nvoglv32.dll!69705b31()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!696215b0()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 4
=========================================================================
nvoglv32.dll!69621881()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69714ba0()
nvoglv32.dll!6970416c()
[EMAIL PROTECTED]() + 0x3b bytes
[EMAIL PROTECTED]() + 0xd5 bytes
[EMAIL PROTECTED]() + 0x8e bytes
osg50-osgViewerd.dll!osgViewer::GraphicsWindowWin32::makeCurrentImplementation()
Line 1701 + 0x1c bytes C++
> osg50-osgd.dll!osg::GraphicsContext::makeCurrent() Line 512 + 0xf
bytes C++
osg50-osgd.dll!osg::GraphicsThread::run() Line 35 C++
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void
* data=0x0232e97c) Line 113 + 0xf bytes C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x02362ef8) Line 331 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 5
=========================================================================
[EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x6 bytes
nvoglv32.dll!69621949()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69714ba0()
nvoglv32.dll!697046aa()
[EMAIL PROTECTED]() + 0x97 bytes
[EMAIL PROTECTED]() + 0x169 bytes
[EMAIL PROTECTED]() + 0x8e bytes
osg50-osgViewerd.dll!osgViewer::GraphicsWindowWin32::makeCurrentImplementation()
Line 1693 + 0x1c bytes C++
> osg50-osgd.dll!osg::GraphicsContext::makeCurrent() Line 512 + 0xf
bytes C++
osg50-osgd.dll!osg::GraphicsThread::run() Line 35 C++
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void
* data=0x0234a61c) Line 113 + 0xf bytes C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x02363148) Line 331 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 6
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0xc8 bytes
[EMAIL PROTECTED]() - 0x4b84 bytes
[EMAIL PROTECTED]() + 0x281 bytes
nvoglv32.dll!6970568f()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69621c04()
nvoglv32.dll!69714ec9()
nvoglv32.dll!6962149a()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 7
=========================================================================
[EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x6 bytes
nvoglv32.dll!69621949()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69714ba0()
nvoglv32.dll!697046aa()
[EMAIL PROTECTED]() + 0x97 bytes
[EMAIL PROTECTED]() + 0x169 bytes
[EMAIL PROTECTED]() + 0x8e bytes
osg50-osgViewerd.dll!osgViewer::GraphicsWindowWin32::makeCurrentImplementation()
Line 1693 + 0x1c bytes C++
> osg50-osgd.dll!osg::GraphicsContext::makeCurrent() Line 512 + 0xf
bytes C++
osg50-osgd.dll!osg::GraphicsThread::run() Line 35 C++
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void
* data=0x0234b2fc) Line 113 + 0xf bytes C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x023635e8) Line 331 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 8
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x6 bytes
nvoglv32.dll!69761ee8()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!697653c6()
nvoglv32.dll!6973029b()
[EMAIL PROTECTED]() + 0x5d bytes
nvoglv32.dll!69704ab9()
nvoglv32.dll!69714e96()
nvoglv32.dll!6962149a()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 9
=========================================================================
[EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x6 bytes
nvoglv32.dll!69621949()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69714ba0()
nvoglv32.dll!697046aa()
[EMAIL PROTECTED]() + 0x97 bytes
[EMAIL PROTECTED]() + 0x169 bytes
[EMAIL PROTECTED]() + 0x8e bytes
osg50-osgViewerd.dll!osgViewer::GraphicsWindowWin32::makeCurrentImplementation()
Line 1693 + 0x1c bytes C++
> osg50-osgd.dll!osg::GraphicsContext::makeCurrent() Line 512 + 0xf
bytes C++
osg50-osgd.dll!osg::GraphicsThread::run() Line 35 C++
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void
* data=0x022d4c04) Line 113 + 0xf bytes C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x0237d230) Line 331 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 10
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0xc8 bytes
[EMAIL PROTECTED]() - 0x4b84 bytes
[EMAIL PROTECTED]() + 0x281 bytes
nvoglv32.dll!6970568f()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!6970490f()
nvoglv32.dll!69714e96()
nvoglv32.dll!6962149a()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 11
=========================================================================
[EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0x6 bytes
nvoglv32.dll!69621949()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!69714ba0()
nvoglv32.dll!697046aa()
[EMAIL PROTECTED]() + 0x97 bytes
[EMAIL PROTECTED]() + 0x169 bytes
[EMAIL PROTECTED]() + 0x8e bytes
osg50-osgViewerd.dll!osgViewer::GraphicsWindowWin32::makeCurrentImplementation()
Line 1693 + 0x1c bytes C++
> osg50-osgd.dll!osg::GraphicsContext::makeCurrent() Line 512 + 0xf
bytes C++
osg50-osgd.dll!osg::GraphicsThread::run() Line 35 C++
ot11-OpenThreadsd.dll!OpenThreads::ThreadPrivateActions::StartThread(void
* data=0x022ef24c) Line 113 + 0xf bytes C++
msvcr80d.dll!_callthreadstartex() Line 348 + 0xf bytes C
msvcr80d.dll!_threadstartex(void * ptd=0x0237d6d0) Line 331 C
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 12
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0xc8 bytes
[EMAIL PROTECTED]() - 0x4b84 bytes
[EMAIL PROTECTED]() + 0x281 bytes
nvoglv32.dll!6970568f()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!6970490f()
nvoglv32.dll!69714e96()
nvoglv32.dll!6962149a()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
Thread 13
=========================================================================
> [EMAIL PROTECTED]()
[EMAIL PROTECTED]() + 0xc bytes
[EMAIL PROTECTED]() + 0xc8 bytes
[EMAIL PROTECTED]() - 0x4b84 bytes
[EMAIL PROTECTED]() + 0x281 bytes
nvoglv32.dll!6970568f()
[Frames below may be incorrect and/or missing, no symbols loaded
for nvoglv32.dll]
nvoglv32.dll!696fdaba()
nvoglv32.dll!69704735()
nvoglv32.dll!69714e96()
nvoglv32.dll!6962149a()
nvoglv32.dll!69621f14()
nvoglv32.dll!697057a9()
[EMAIL PROTECTED]@12() + 0x12 bytes
[EMAIL PROTECTED]() + 0x27 bytes
[EMAIL PROTECTED]() + 0x1b bytes
--
______________________________________________________
Jean-Sebastien Guay [EMAIL PROTECTED]
http://www.cm-labs.com/
http://whitestar02.webhop.org/
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This application is open source and may be redistributed and/or modified
* freely and without restriction, both in commericial and non commericial
applications,
* as long as this copyright notice is maintained.
*
* This application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <osgDB/ReadFile>
#include <osgUtil/Optimizer>
#include <osg/CoordinateSystemNode>
#include <osg/Switch>
#include <osgText/Text>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <iostream>
void addEventHandlers(osgViewer::View* view)
{
// set up the camera manipulators.
view->setCameraManipulator( new osgGA::TrackballManipulator() );
// add the state manipulator
view->addEventHandler( new
osgGA::StateSetManipulator(view->getCamera()->getOrCreateStateSet()) );
// add the thread model handler
view->addEventHandler(new osgViewer::ThreadingHandler);
// add the window size toggle handler
view->addEventHandler(new osgViewer::WindowSizeHandler);
// add the stats handler
view->addEventHandler(new osgViewer::StatsHandler);
// add the record camera path handler
view->addEventHandler(new osgViewer::RecordCameraPathHandler);
// add the LOD Scale handler
view->addEventHandler(new osgViewer::LODScaleHandler);
// add the screen capture handler
view->addEventHandler(new osgViewer::ScreenCaptureHandler);
}
class AddViewHandler : public osgGA::GUIEventHandler
{
public:
AddViewHandler(osgViewer::CompositeViewer* viewer, osg::Node* sceneRoot)
: _viewer(viewer), _sceneRoot(sceneRoot) {}
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN &&
ea.getKey()== 'a')
{
osgViewer::View* view = new osgViewer::View;
view->setUpViewInWindow(50, 50, 800, 600);
view->getCamera()->getGraphicsContext()->realize();
view->setSceneData(_sceneRoot.get());
addEventHandlers(view);
_viewer->stopThreading();
_viewer->addView(view);
_viewer->startThreading();
return true;
}
return false;
}
protected:
osg::ref_ptr<osgViewer::CompositeViewer> _viewer;
osg::ref_ptr<osg::Node> _sceneRoot;
};
int main(int argc, char** argv)
{
// use an ArgumentParser object to manage the program arguments.
osg::ArgumentParser arguments(&argc,argv);
arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+"
is the standard OpenSceneGraph example which loads and visualises 3d models.");
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+"
[options] filename ...");
arguments.getApplicationUsage()->addCommandLineOption("--image
<filename>","Load an image and render it on a quad");
arguments.getApplicationUsage()->addCommandLineOption("--dem
<filename>","Load an image/DEM and render it on a HeightField");
arguments.getApplicationUsage()->addCommandLineOption("--login <url>
<username> <password>","Provide authentication information for http file
access.");
osgViewer::CompositeViewer viewer(arguments);
unsigned int helpType = 0;
if ((helpType = arguments.readHelpType()))
{
arguments.getApplicationUsage()->write(std::cout, helpType);
return 1;
}
// report any errors if they have occurred when parsing the program
arguments.
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return 1;
}
if (arguments.argc()<=1)
{
arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
return 1;
}
std::string url, username, password;
while(arguments.read("--login",url, username, password))
{
if (!osgDB::Registry::instance()->getAuthenticationMap())
{
osgDB::Registry::instance()->setAuthenticationMap(new
osgDB::AuthenticationMap);
osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(
url,
new osgDB::AuthenticationDetails(username, password)
);
}
}
osg::ref_ptr<osgViewer::View> defaultView = new osgViewer::View;
viewer.addView(defaultView.get());
addEventHandlers(defaultView.get());
// load the data
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
if (!loadedModel)
{
std::cout << arguments.getApplicationName() <<": No data loaded" <<
std::endl;
return 1;
}
// any option left unread are converted into errors to write out later.
arguments.reportRemainingOptionsAsUnrecognized();
// report any errors if they have occurred when parsing the program
arguments.
if (arguments.errors())
{
arguments.writeErrorMessages(std::cout);
return 1;
}
// optimize the scene graph, remove redundant nodes and state etc.
osgUtil::Optimizer optimizer;
optimizer.optimize(loadedModel.get());
defaultView->setSceneData( loadedModel.get() );
defaultView->setUpViewInWindow(50, 50, 800, 600);
defaultView->addEventHandler(new AddViewHandler(&viewer,
loadedModel.get()));
viewer.realize();
return viewer.run();
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org