[osg-users] [Any feedback welcome] possible lack of robustness of the VAO path
Julien Valentin
julienvalentin51 at gmail.com
Tue Jan 15 08:23:00 PST 2019
I mod a bit 3.6 branch so only 99% sure of this behavior
Please confirm the bug (don't forget to set OSG_VERTEX_BUFFER_HINT=VAO)
Code:
#include <osgUtil/MeshOptimizers>
#include <osgGA/TrackballManipulator>
#include <osgGA/FirstPersonManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
class GeomLoaderCB : public osg::Camera::DrawCallback//
// osg::NodeCallback
{
public:
int _thresremoval;int _nbaddedatatime;
GeomLoaderCB(int thresremoval=1,int nbaddedatatime=1):_nbaddedatatime(nbaddedatatime),_thresremoval(thresremoval) {}
mutable std::list<osg::ref_ptr<osg::Geometry> > _geoms;
void setGeometryList(osgUtil::GeometryCollector::GeometryList c) {
for(auto f : c)
_geoms.push_back(f);
}
virtual void operator () (const osg::Camera& camera ) const {
osg::Node * node=const_cast<osg::Camera*>(&camera)->getChild(0);
if(_geoms.empty())return;
osg::ref_ptr<osg::Group> gr =new osg::Group;
osg::ref_ptr<osg::Group> gr2 = node->asGroup();
if(gr2->getNumChildren()>_thresremoval)
{
OSG_WARN<<"removal"<<std::endl;
osg::ref_ptr<osg::Geode > ge=gr2->getChild(0)->asGroup()->getChild(0)->asGeode();
for(int i=0; i<ge->getNumChildren(); ++i) {
osg::ref_ptr <osg::Geometry >g=ge->getChild(i)->asGeometry();
ge->removeChild(g );
OSG_WARN<<g->referenceCount()<<std::endl;
}
gr2->removeChildren(0,1);
return;
}
std::list<osg::ref_ptr<osg::Geometry> > ::iterator it= _geoms.begin();
int cpt=0;
while(it!=_geoms.end()&&cpt++<_nbaddedatatime ) {
osg::Geode* ge=(new osg::Geode);
ge->addChild((*it));
gr->addChild((ge));
OSG_WARN<<"addage"<< (*it ) ->getVertexArray()->getNumElements()<<std::endl;
it=_geoms.erase(it);
}
gr2->addChild(gr);
}
};
/// This demo reproduce a bug
/// it add drawables given in arg one by one and then remove them
/// in theory only 3 geometries should be display at the same time (see GeomLoaderCB)
int main(int argc, char **argv)
{
osg::ArgumentParser args(&argc,argv);
unsigned int geomcountaddedatatime=1,geomcountabovewichweremove=2;//problem began with 2
while(args.read("--add",geomcountaddedatatime) ) { }
while(args.read("--remove",geomcountabovewichweremove) ) { }
osgUtil::GeometryCollector geomcollector(0,osgUtil::Optimizer::ALL_OPTIMIZATIONS);
osg::ref_ptr<osg::Node > loaded=osgDB::readNodeFiles(args);
if(loaded.valid())
{
loaded->accept(geomcollector);
osg::Group * root=new osg::Group;
GeomLoaderCB * loader=new GeomLoaderCB(geomcountabovewichweremove,geomcountaddedatatime);
loader->setGeometryList( geomcollector.getGeometryList() );
osgViewer::Viewer viewer;
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::ThreadingHandler);
viewer.realize();
viewer.setSceneData( root);
viewer.getCamera()->setFinalDrawCallback(loader);
loaded=0;
viewer.run();
}
}
mp3butcher wrote:
> Hi all,
> I wrote a sample code exibiting crash with my scene
> https://github.com/openscenegraph/OpenSceneGraph/issues/692
>
> If you'd have 5 min to waste, i would be glad you confirm with your own scene...
>
> Thank you!
>
> Cheers,
> Julien
------------------------
Twirling twirling twirling toward freedom
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75497#75497
More information about the osg-users
mailing list