<div>Hi Cully,</div><div>    It seems like the problem that split window or frame buffer to different part.</div><div>    There are two way to do this in osg.</div><div>    1.add slave camera to osgViewer::view,each camera has different graphiccontext.</div><div>    2.add osgViewer::view to osgViewer::compositeViewer,and one osgViewer::view correspond one camera,and has the same graphiccontext.</div><div><br></div><div>method 1 prefer the situation that each camera has different view or proj matrix but has same node tree.like Virtual Reality rendering,or cad design.</div><div>method 2 prefer each view(camera) has independent node tree.Like multi-doc edit in Word.</div><div><br></div><div>And the thread problem,I think you'd better do update in osg update thread,like add updateCallback to node.By this way,your thread will not have sync problem with osg render thread.</div><div><br></div><div>To be honest,I don't pretty understand your problem.</div><div>you'd better simplify your code to a problem example.</div><div><br></div><div>Qi Yu.</div><div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From:</b> "Antoine Cully"<antoinecully@hotmail.com>;</div><div><b>Date:</b> Thu, May 23, 2019 00:49 AM</div><div><b>To:</b> "osg-users"<osg-users@lists.openscenegraph.org>;<wbr></div><div></div><div><b>Subject:</b> [osg-users] Running multiple (independent) viewers in differentthreads</div></div><div><br></div>Dear OSG Community, <br><br>I searched quite a lot through the source code and the beginner guide, but I was unable to find a way to make this work, so I am posting here hoping that you could help me. <br><br>I am developing a tool to run physical simulations (of robots) in parallel. This tool is used to run stochastic optimisation (like deep reinforcement learning) algorithms, and for this I need to be able to run several, but fully independent, simulations in parallel thanks to multithreading. This enables to collect data faster and for instance with a 32-core multithreaded CPU the speed-up factor is quite significant. <br><br>In each simulation, I have one camera that observes the environment, and which can be used to change the behaviour of the robot running in this simulation. The camera is currently implemented as a pbuffer following closely the osgscreencapture example. The actual code of the camera can be found on github, but apprently I am not allowed to post URLs at the moment. <br>The multithreading is managed by TBB (an Intel library that I have been using for 6 years now). <br><br>If I run my code in a "sequential mode", i.e., all the simulations running one after the other, everything is going well.  However, if I run it in parallel, then I have some unstable behaviours. For instance, I can have a segmentation fault happening after a random number of simulations or suddenly after again a random number of simulations, the pbuffer cannot be created anymore (OSG displays "Error: Unable to create pbuffer."). It seems to me that "::osg::ref_ptr<::osg::GraphicsContext> pbuffer =  ::osg::GraphicsContext::createGraphicsContext(traits.get()); "<br>does not work in this setup. <br><br>If I remove the cameras (and all OSG components) from my code, it is working well in parallel, but of course I would like to have cameras in my simulations. <br><br>Ideally, I would like to run OSG in a single-thread mode and let TBB distribute the different instances of the simulator and OSG in different threads, but even with "setThreadingModel(osgViewer::ViewerBase::ThreadingModel::SingleThreaded);" it does not work. <br>I tried different threading modes, with the same result.<br><br>So here is my question: <br>What would be the most appropriate way to run several independent viewers and pbuffers, each in a different thread? <br>The rendered scenes are really simple (no texture, just several primitive shapes) and I am only rendering a couple of frames in each simulation, so I don't need a complex threading model for OSG. <br><br><br>Some information about my system:<br>- Ubuntu 18.04<br>- OSG 3.6.4<br><br>Thank you in advance for your help. <br><br>Best regards, <br><br>Antoine<br><br>------------------<br>Read this topic online here:<br>http://forum.openscenegraph.org/viewtopic.php?p=76134#76134<br><br><br><br><br><br>_______________________________________________<br>osg-users mailing list<br>osg-users@lists.openscenegraph.org<br>http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org<br></div>