[osg-users] problem with recycled context id's and OPTIMIZE_TEXTURE_SETTINGS
Brett Wiesner
brettwiesner at gmail.com
Thu Jul 17 13:31:58 PDT 2008
Hi,
Problem:
Using OSG 2.4.0 I have built an app that dynamically creates composite
viewers that have one of more views. The scene graph is kept around as a
ref pointer during the course of multiple viewers. When I delete a
composite viewer and create another one and then use the original root
node of the scene graph, textures are gone (ie, everythings white).
I've tracked the problem down to this. If you optimize your scene graph
using the OPTIMIZE_TEXTURE_SETTINGS setting, then recycle the context
id, textures are missing.
I'm honestly not sure what the optimizer option
OPTIMIZE_TEXTURE_SETTINGS does but I can reproduce the bug.
I've included sample code below to reproduce the bug.
Thanks,
Brett
// This method reads in a flt file and writes it out optimized using the
"troublesome" flag.
writeOutModelAsIveOptimized()
{
std::string modelPath = testDataDir();
modelPath += "testTree\\Test_tree.flt";
std::string modelPathOut = testDataDir();
modelPathOut += "testTree\\Test_tree_optimized.ive";
// create a scene graph (and keep it around).
osg::ref_ptr<osg::Node> modelNode = osgDB::readNodeFile(modelPath);
osgUtil::Optimizer op;
op.optimize(modelNode.get(),osgUtil::Optimizer::OPTIMIZE_TEXTURE_SETTINGS);
osgDB::writeNodeFile(*modelNode.get(), modelPathOut);
}
// This method reads in a flt file and writes it out unoptimized. Please
substitute any flt file you have.
writeOutModelAsIve()
{
std::string modelPath = testDataDir();
modelPath += "testTree\\Test_tree.flt";
std::string modelPathOut = testDataDir();
modelPathOut += "testTree\\Test_tree_unoptimized.ive";
// create a scene graph (and keep it around).
osg::ref_ptr<osg::Node> modelNode = osgDB::readNodeFile(modelPath);
osgDB::writeNodeFile(*modelNode.get(), modelPathOut);
}
// This method creates a scene graph and keeps it around after the
destruction of a viewer.
// Then it creates a viewer and loads the model. You try this with both
the unoptimized ive and the
// optimized one. It runs the viewer waits for you to look at the model
and then hit esc to quit.
// Then it destroys the viewer, and creates another one using the same
scene graph.
// You'll notice that the scene no longer has textures.
TEST(test_osgKeepSceneGraphAround)
{
std::string modelPath = testDataDir();
modelPath += "testTree\\Test_tree_optimized.ive";
// create a scene graph (and keep it around).
osg::ref_ptr<osg::Node> modelNode = osgDB::readNodeFile(modelPath);
// create viewer1 and set the scene graph data.
osgViewer::Viewer* viewer1 = new osgViewer::Viewer;
viewer1->setUpViewOnSingleScreen(0);
viewer1->setSceneData(modelNode.get());
viewer1->setCameraManipulator(new osgGA::TrackballManipulator());
// render
viewer1->realize();
while(!viewer1->done())
{
viewer1->frame();
}
// delete viewer1.
delete viewer1;
viewer1 = 0;
// create viewer2 and set the scene graph data.
osgViewer::Viewer* viewer2 = new osgViewer::Viewer;
viewer2->setUpViewOnSingleScreen(0);
viewer2->setSceneData(modelNode.get());
viewer2->setCameraManipulator(new osgGA::TrackballManipulator());
// render
viewer2->realize();
while(!viewer2->done())
{
viewer2->frame();
}
// delete viewer2.
delete viewer2;
viewer2 = 0;
}
More information about the osg-users
mailing list