OpenSceneGraph
OpenSceneGraph copied to clipboard
Infinite loop when using Optimizer
When I use osgUtil::Optimizer, with option osgUtil::Optimizer::FLATTEN_STATIC_TRANSFORMS on this file.zip, I get an infinite loop at
https://github.com/openscenegraph/OpenSceneGraph/blob/40bddd8d9532620dc704adce0d2fb0c854d62d0f/src/osgUtil/Optimizer.cpp#L255
I use OpenSceneGraph 3.6.5. Here is the dot version of the same file.

Any idea of what could be the reason ?
I came to the conclusion that this is an infinite loop by enabling OSG_DEBUG output. It writes to std output
** RemoveStaticTransformsVisitor *** Pass "<<i
with growing values for i. I stopped it after 1e6.
I have just tried your model on my Xubuntu 18.04 system with the OSG-3.6 branch and the model loads fine with :
osgviewer file.osg
If I run with OSG_NOTIFY_LEVEL env var set to DEBUG and then filter output to see just the Opt related lines I get:
g$ osgviewer file.osg --screen 0 | grep Opt Optimizer::optimize() doing REMOVE_LOADED_PROXY_NODES Optimizer::optimize() doing COMBINE_ADJACENT_LODS Optimizer::optimize() doing OPTIMIZE_TEXTURE_SETTINGS Optimizer::optimize() doing SHARE_DUPLICATE_STATE Optimizer::optimize() doing FLATTEN_STATIC_TRANSFORMS Optimizer::optimize() doing REMOVE_REDUNDANT_NODES Optimizer::optimize() doing MAKE_FAST_GEOMETRY Optimizer::optimize() doing MERGE_GEOMETRY
So FLATTEN_STATIC_TRANSFORMS is running in osgviewer without problems.
What platform are you working on?
After digging a little, reproducing the bug was not straightforward. Here is a minimal not-working example.
#include <iostream>
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osg/Transform>
#include <osg/PositionAttitudeTransform>
#include <osg/MatrixTransform>
void test()
{
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("/tmp/file.osg");
{
osg::Vec3f scale (1, 1, 1);
osg::ref_ptr<osg::MatrixTransform> xform = new osg::MatrixTransform;
//xform->setDataVariance( osg::Object::STATIC );
xform->setMatrix( osg::Matrix::scale( scale ) );
xform->addChild( node );
// This two lines below only work when data variance of xform is not set to STATIC.
//osgUtil::Optimizer optimizer;
//optimizer.optimize(xform, osgUtil::Optimizer::DEFAULT_OPTIMIZATIONS);
node = xform;
}
{
// This works no matter what the data variance is.
osgUtil::Optimizer optimizer;
optimizer.optimize(node, osgUtil::Optimizer::DEFAULT_OPTIMIZATIONS);
}
}
int main()
{
test();
return 0;
}
I am on Ubuntu 18.04.
When you say non-working, do you mean it crashes, or just doesn't compile?
On Wed, 13 Jan 2021 at 15:41, Joseph Mirabel [email protected] wrote:
After digging a little, reproducing the bug was not straightforward. Here is a minimal not-working example.
#include
#include <osgUtil/Optimizer> #include <osgDB/ReadFile> #include <osg/Transform> #include <osg/PositionAttitudeTransform> #include <osg/MatrixTransform> void test() { osg::ref_ptrosg::Node node = osgDB::readNodeFile("/tmp/file.osg");
{ osg::Vec3f scale (1, 1, 1); osg::ref_ptrosg::MatrixTransform xform = new osg::MatrixTransform; //xform->setDataVariance( osg::Object::STATIC ); xform->setMatrix( osg::Matrix::scale( scale ) ); xform->addChild( node );
// This two lines below only work when data variance of xform is not set to STATIC. //osgUtil::Optimizer optimizer; //optimizer.optimize(xform, osgUtil::Optimizer::DEFAULT_OPTIMIZATIONS); node = xform;}
{ // This works no matter what the data variance is. osgUtil::Optimizer optimizer; optimizer.optimize(node, osgUtil::Optimizer::DEFAULT_OPTIMIZATIONS); } } int main() { test(); return 0; }
I am on Ubuntu 18.04.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openscenegraph/OpenSceneGraph/issues/1020#issuecomment-759531268, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABUA26GVLPL6DMZ26SCLA3SZW5J5ANCNFSM4WARMLNQ .
As it is above, it terminates with no problem.
If you play with the comments, i.e. uncomment the setDataVariance and the commented optimize call, then it runs into an infinite loops (If not infinite, at least very long).
I realize I have been impolite by not saying hello nor thanks. So hello, and thank you for this wonderful library and the time you take for my issue.