Hi,

I'm encountering a segfault in several applications that use osgShadow
when the application is closing. I've reduced the problem to a very
simple example using osgShadow (see attachment).

I'm using OSG 2.8.0 with VC9. The example program only crashes for me in
Debug mode (the failure is just silent in Release).

After some lengthy investigations, I tracked the bug down to some
changes made in revision 9549 (files State and State.cpp).

What happens in the example is that a State object adds itself as an
observer on a PerContextProgram, but never removes itself from the
observer list. The State object is destroyed first, followed by the
PerContextProgram. In the PerContextProgram destructor,
osg::~Referenced() tries to notify its observers that the object is
being destroyed. But because the State object is already deleted, this
causes a nice segfault.

The thing is that the State object is trying to remove itself as an
observer when destroyed (cf. State::~State(), State.cpp, lines 93 to
98). But it fails to correctly do so, as its tracking list has been
previously erased (cf. State::reset(), State.cpp, line 198), leaving the
observer/observe relation in a dangerous state.


Proposed fix:

Do something similar to what is done in State destructor in
State::reset(), before line 198. Namely:

    for(AppliedProgramObjectSet::iterator itr =
_appliedProgramObjectSet.begin();
        itr != _appliedProgramObjectSet.end();
        ++itr)
    {
        (*itr)->removeObserver(this);
    }


Robert, can you confirm this?


Regards,

Tanguy


PS: I'm going away for several days, so I won't be able to prepare a
proper submission before at least Monday or Tuesday.


Attachment: main.cpp
Description: main.cpp

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to