openscenegraph / OpenSceneGraph

OpenSceneGraph git repository
http://www.openscenegraph.org
Other
3.25k stars 1.42k forks source link

In some cases, osgDB::writeNodeFile write 0kb osgb #1288

Open autel-liuxiaozi opened 11 months ago

autel-liuxiaozi commented 11 months ago

Hello,I think it's a bug and recurrent Very occasionally. using osg3.4.0

I uses osg lib to write osgb file , code like this


osg::ref_ptr<osg::Group> group = new osg::Group;
for(const auto& child : tile->children_)   
{
    if (child == nullptr)
        continue;

    osg::ref_ptr<osg::PagedLOD> paged_lod = new osg::PagedLOD;

    paged_lod->setRangeMode(osg::PagedLOD::PIXEL_SIZE_ON_SCREEN);
    paged_lod->setCenterMode(osg::PagedLOD::USER_DEFINED_CENTER);

    Vector3f center = child->box_.center();
    Vector3f corner = child->box_.corner(BoundingBox3f::CornerType(0));

    paged_lod->setCenter(osg::Vec3f(center(0), center(1), center(2)));

    const float radius = (center - corner).norm();

    if (!child->children_.empty())
    {
        const int level = GeometricErrorToLevel(child->geometric_error_);
        const float pixel_size = radius / LevelToGSD(level);

        paged_lod->addChild(child->osg_node_, 0, pixel_size);
        paged_lod->setFileName(1, child->url_ + ".osgb");
        paged_lod->setRange(1, pixel_size, FLT_MAX);
    }
    else
    {
        paged_lod->addChild(child->osg_node_, 0, FLT_MAX);
    }
    group->addChild(paged_lod);
}
if(group->getNumChildren() > 0)
    osgDB::writeNodeFile(*group, file_name new osgDB::Options("WritelmageHint=IncludeFile"));
for(auto& child : tile->children_)
    child = nullptr; //release tile after save

now demo crashes in osgDB::writeNodeFile(*group, file_name new osgDB::Options("WritelmageHint=IncludeFile"));

and have some error like this: image

and saved osgb is like this: image

could anyone help me to locate this bug? @robertosfield @andesengineering @openscenegraph

thank you all very much

autel-liuxiaozi commented 11 months ago

it's in a omp condition, just like this:

#pragma omp parallel for schedule(dynamic,1)
for(int i=0;i<node.size();++i)
{
SaveTileAsOsgb(names[i],tile);
}

and this stack info like this: image

robertosfield commented 11 months ago

My best guess is memory corruption somewhere in your application. Your code snippet has references to class that aren't part of the OSG so we can only guess what functionality they might have.

You have all your application, all your data and you have access so all of the OSG code base, while we only have the later. You are the one best place to investigate the problem. Try building with a debugger and stepping through the code, or try running your application in a tool like valgrind to see if can spot any memory corruption.

autel-liuxiaozi commented 11 months ago

My best guess is memory corruption somewhere in your application. Your code snippet has references to class that aren't part of the OSG so we can only guess what functionality they might have.

You have all your application, all your data and you have access so all of the OSG code base, while we only have the later. You are the one best place to investigate the problem. Try building with a debugger and stepping through the code, or try running your application in a tool like valgrind to see if can spot any memory corruption.

ok, thank you. but this happens only when generate osgbs. so I guess it's related to osg library,and happens very occasionally

robertosfield commented 11 months ago

Memory corruption in one place can cause other parts to crash.

Even if it does turn out to be an OSG bug, at this point there isn't anything that others can help with given no others have reported this issue, we don't have a means of recreating the problem. You are the only one that has means to investigate.

autel-liuxiaozi commented 11 months ago

OK, thank you