Fixed crash on exit issues with osgFX, osgParticle, osgSim and the osgforest example

This commit is contained in:
Robert Osfield 2019-01-07 17:46:02 +00:00
parent 5e9be10da6
commit 1c65815f4e
11 changed files with 150 additions and 16 deletions

View File

@ -803,6 +803,18 @@ class ShaderGeometry : public osg::Drawable
typedef std::vector<osg::Vec4> PositionSizeList;
virtual void resizeGLObjectBuffers(unsigned int maxSize)
{
osg::Drawable::resizeGLObjectBuffers(maxSize);
if (_geometry) _geometry->resizeGLObjectBuffers(maxSize);
}
virtual void releaseGLObjects(osg::State* state) const
{
osg::Drawable::releaseGLObjects(state);
if (_geometry) _geometry->releaseGLObjects(state);
}
virtual void drawImplementation(osg::RenderInfo& renderInfo) const
{
for(PositionSizeList::const_iterator itr = _trees.begin();

View File

@ -119,6 +119,9 @@ namespace osgFX
/** default traversal */
inline void inherited_traverse(osg::NodeVisitor& nv);
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state = 0) const;
protected:
virtual ~Effect();
Effect &operator=(const Effect &) { return *this; }

View File

@ -37,8 +37,10 @@ namespace osgParticle
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const PrecipitationEffect*>(obj) != 0; }
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
virtual void traverse(osg::NodeVisitor& nv);
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state = 0) const;
virtual void traverse(osg::NodeVisitor& nv);
/** Set all the parameters to create an rain effect of specified intensity.*/
void rain(float intensity);
@ -117,6 +119,9 @@ namespace osgParticle
void setNumberOfVertices(unsigned int numVertices) { _numberOfVertices = numVertices; }
unsigned int getNumberOfVertices() const { return _numberOfVertices; }
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state) const;
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
struct Cell
@ -174,7 +179,7 @@ namespace osgParticle
protected:
virtual ~PrecipitationDrawable() {}
virtual ~PrecipitationDrawable();
bool _requiresPreviousMatrix;

View File

@ -240,6 +240,10 @@ public:
/** recompute the primitives rendering meshes/lines thtat represent the sphere segment.*/
void updatePrimitives();
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* state = 0) const;
virtual osg::BoundingSphere computeBound() const;
private:

View File

@ -385,6 +385,8 @@ QueryGeometry::getNumPixels( const osg::Camera* cam )
void
QueryGeometry::releaseGLObjects( osg::State* state ) const
{
Geometry::releaseGLObjects(state);
if (!state)
{
// delete all query IDs for all contexts.

View File

@ -135,6 +135,20 @@ void Effect::traverse(osg::NodeVisitor& nv)
// wow, we're finished! :)
}
void Effect::resizeGLObjectBuffers(unsigned int maxSize)
{
Group::resizeGLObjectBuffers(maxSize);
if (_dummy_for_validation) _dummy_for_validation->resizeGLObjectBuffers(maxSize);
}
void Effect::releaseGLObjects(osg::State* state) const
{
Group::releaseGLObjects(state);
if (_dummy_for_validation) _dummy_for_validation->releaseGLObjects(state);
}
void Effect::build_dummy_node()
{
_dummy_for_validation = new osg::Geode;

View File

@ -659,6 +659,8 @@ osg::BoundingBox osgParticle::ParticleSystem::computeBoundingBox() const
void osgParticle::ParticleSystem::resizeGLObjectBuffers(unsigned int maxSize)
{
Drawable::resizeGLObjectBuffers(maxSize);
_bufferedArrayData.resize(maxSize);
for(unsigned int i=0; i<_bufferedArrayData.size(); ++i)
{
@ -668,6 +670,8 @@ void osgParticle::ParticleSystem::resizeGLObjectBuffers(unsigned int maxSize)
void osgParticle::ParticleSystem::releaseGLObjects(osg::State* state) const
{
Drawable::releaseGLObjects(state);
if (state)
{
_bufferedArrayData[state->getContextID()].releaseGLObjects(state);

View File

@ -121,22 +121,64 @@ void PrecipitationEffect::snow(float intensity)
void PrecipitationEffect::compileGLObjects(osg::RenderInfo& renderInfo) const
{
if (_quadGeometry.valid())
{
_quadGeometry->compileGLObjects(renderInfo);
if (_quadGeometry->getStateSet()) _quadGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
}
if (_quadGeometry.valid()) _quadGeometry->compileGLObjects(renderInfo);
if (_lineGeometry.valid()) _lineGeometry->compileGLObjects(renderInfo);
if (_pointGeometry.valid()) _pointGeometry->compileGLObjects(renderInfo);
if (_lineGeometry.valid())
{
_lineGeometry->compileGLObjects(renderInfo);
if (_lineGeometry->getStateSet()) _lineGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
}
if (_quadStateSet.valid()) _quadStateSet->compileGLObjects(*renderInfo.getState());
if (_lineStateSet.valid()) _lineStateSet->compileGLObjects(*renderInfo.getState());
if (_pointStateSet.valid()) _pointStateSet->compileGLObjects(*renderInfo.getState());
if (_pointGeometry.valid())
for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin();
itr != _viewDrawableMap.end();
++itr)
{
_pointGeometry->compileGLObjects(renderInfo);
if (_pointGeometry->getStateSet()) _pointGeometry->getStateSet()->compileGLObjects(*renderInfo.getState());
const PrecipitationDrawableSet& pds = itr->second;
if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->compileGLObjects(renderInfo);
if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->compileGLObjects(renderInfo);
if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->compileGLObjects(renderInfo);
}
}
void PrecipitationEffect::resizeGLObjectBuffers(unsigned int maxSize)
{
if (_quadGeometry.valid()) _quadGeometry->resizeGLObjectBuffers(maxSize);
if (_lineGeometry.valid()) _lineGeometry->resizeGLObjectBuffers(maxSize);
if (_pointGeometry.valid()) _pointGeometry->resizeGLObjectBuffers(maxSize);
if (_quadStateSet.valid()) _quadStateSet->resizeGLObjectBuffers(maxSize);
if (_lineStateSet.valid()) _lineStateSet->resizeGLObjectBuffers(maxSize);
if (_pointStateSet.valid()) _pointStateSet->resizeGLObjectBuffers(maxSize);
for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin();
itr != _viewDrawableMap.end();
++itr)
{
const PrecipitationDrawableSet& pds = itr->second;
if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->resizeGLObjectBuffers(maxSize);
if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->resizeGLObjectBuffers(maxSize);
if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->resizeGLObjectBuffers(maxSize);
}
}
void PrecipitationEffect::releaseGLObjects(osg::State* state) const
{
if (_quadGeometry.valid()) _quadGeometry->releaseGLObjects(state);
if (_lineGeometry.valid()) _lineGeometry->releaseGLObjects(state);
if (_pointGeometry.valid()) _pointGeometry->releaseGLObjects(state);
if (_quadStateSet.valid()) _quadStateSet->releaseGLObjects(state);
if (_lineStateSet.valid()) _lineStateSet->releaseGLObjects(state);
if (_pointStateSet.valid()) _pointStateSet->releaseGLObjects(state);
for(ViewDrawableMap::const_iterator itr = _viewDrawableMap.begin();
itr != _viewDrawableMap.end();
++itr)
{
const PrecipitationDrawableSet& pds = itr->second;
if (pds._quadPrecipitationDrawable.valid()) pds._quadPrecipitationDrawable->releaseGLObjects(state);
if (pds._linePrecipitationDrawable.valid()) pds._linePrecipitationDrawable->releaseGLObjects(state);
if (pds._pointPrecipitationDrawable.valid()) pds._pointPrecipitationDrawable->releaseGLObjects(state);
}
}
@ -829,7 +871,24 @@ PrecipitationEffect::PrecipitationDrawable::PrecipitationDrawable(const Precipit
{
}
PrecipitationEffect::PrecipitationDrawable::~PrecipitationDrawable()
{
OSG_NOTICE<<"PrecipitationEffect::~PrecipitationDrawable() "<<this<<std::endl;
}
void PrecipitationEffect::PrecipitationDrawable::resizeGLObjectBuffers(unsigned int maxSize)
{
Drawable::resizeGLObjectBuffers(maxSize);
if (_geometry) _geometry->resizeGLObjectBuffers(maxSize);
}
void PrecipitationEffect::PrecipitationDrawable::releaseGLObjects(osg::State* state) const
{
Drawable::releaseGLObjects(state);
if (_geometry) _geometry->releaseGLObjects(state);
}
void PrecipitationEffect::PrecipitationDrawable::drawImplementation(osg::RenderInfo& renderInfo) const
{

View File

@ -54,6 +54,11 @@ LightPointDrawable::LightPointDrawable(const LightPointDrawable& lpd,const osg::
{
}
LightPointDrawable::~LightPointDrawable()
{
OSG_NOTICE<<"LightPointDrawable::~LightPointDrawable()"<<std::endl;
}
void LightPointDrawable::reset()
{
SizedLightPointList::iterator itr;

View File

@ -102,7 +102,7 @@ class OSGSIM_EXPORT LightPointDrawable : public osg::Drawable
protected:
virtual ~LightPointDrawable() {}
virtual ~LightPointDrawable();
osg::Endian _endian;

View File

@ -93,6 +93,32 @@ void SphereSegment::traverse(osg::NodeVisitor& nv)
}
}
void SphereSegment::resizeGLObjectBuffers(unsigned int maxSize)
{
if (_surfaceGeometry.valid()) _surfaceGeometry->resizeGLObjectBuffers(maxSize);
if (_spokesGeometry.valid()) _spokesGeometry->resizeGLObjectBuffers(maxSize);
if (_edgeLineGeometry.valid()) _edgeLineGeometry->resizeGLObjectBuffers(maxSize);
if (_sidesGeometry.valid()) _sidesGeometry->resizeGLObjectBuffers(maxSize);
if (_litOpaqueState.valid()) _litOpaqueState->resizeGLObjectBuffers(maxSize);
if (_unlitOpaqueState.valid()) _unlitOpaqueState->resizeGLObjectBuffers(maxSize);
if (_litTransparentState.valid()) _litTransparentState->resizeGLObjectBuffers(maxSize);
if (_unlitTransparentState.valid()) _unlitTransparentState->resizeGLObjectBuffers(maxSize);
}
void SphereSegment::releaseGLObjects(osg::State* state) const
{
if (_surfaceGeometry.valid()) _surfaceGeometry->releaseGLObjects(state);
if (_spokesGeometry.valid()) _spokesGeometry->releaseGLObjects(state);
if (_edgeLineGeometry.valid()) _edgeLineGeometry->releaseGLObjects(state);
if (_sidesGeometry.valid()) _sidesGeometry->releaseGLObjects(state);
if (_litOpaqueState.valid()) _litOpaqueState->releaseGLObjects(state);
if (_unlitOpaqueState.valid()) _unlitOpaqueState->releaseGLObjects(state);
if (_litTransparentState.valid()) _litTransparentState->releaseGLObjects(state);
if (_unlitTransparentState.valid()) _unlitTransparentState->releaseGLObjects(state);
}
osg::BoundingSphere SphereSegment::computeBound() const
{
_bbox.init();