Hi,
Sorry for newbee question. But I found that my program memory usage grows up to 
200 k per cycle.
I try to find memory leak and maybe some guru look to this code portion and 
give me some advice. 
(sorry  because on linux when I copy code from qtcreator I've got some mess.)

Code:

      osg::ref_ptr < osg::MatrixTransform > viewnode_mtx;
    osg::ref_ptr < SmokeParticleSystem > smoke_right;

class SmokeParticleSystem : public osg::Group {
private:
   // osgParticle::PointPlacer* placer;
public:
    SmokeParticleSystem(osg::Group* scene, osg::MatrixTransform* 
mt,osg::Uniform *patt)  {
        osgParticle::ParticleSystem* dustParticleSystem = new 
osgParticle::ParticleSystem;
        osg::Geode *geode = new osg::Geode();
        geode->addDrawable(dustParticleSystem);
        this->addChild(geode);

        // dustParticleSystem->setDefaultAttributes("smoke.rgb", false, false);
        osgParticle::Particle smokeParticle;
        smokeParticle.setSizeRange(osgParticle::rangef(1.5f,4.0f)); // meters
        smokeParticle.setLifeTime(10); // seconds
        smokeParticle.setMass(0.2f);
        smokeParticle.setColorRange(osgParticle::rangev4(
                                        osg::Vec4(1, 1.0f, 1.0f, 1.0f),
                                        osg::Vec4(0.8, 0.8, 0.8, 0.0f)));
        dustParticleSystem->setDefaultParticleTemplate(smokeParticle);
        dustParticleSystem->setDefaultAttributesUsingShaders( "smoke.rgb", 
false, 0 );
        osgParticle::ParticleSystemUpdater *dustSystemUpdater = new 
osgParticle::ParticleSystemUpdater;
        dustSystemUpdater->addParticleSystem(dustParticleSystem);
        this->addChild(dustSystemUpdater);
        osgParticle::ModularEmitter *emitter = new osgParticle::ModularEmitter;
        emitter->setParticleSystem(dustParticleSystem);
        this->addChild(emitter);
        dustRate =
                static_cast<osgParticle::RandomRateCounter 
*>(emitter->getCounter());
        dustRate->setRateRange(20,30);
        osgParticle::PointPlacer* placer =
                static_cast<osgParticle::PointPlacer *>(emitter->getPlacer());
        this->setUpdateCallback(new EmitterUpdateCallback(placer, mt));
        osgParticle::RadialShooter* shooter =
                static_cast<osgParticle::RadialShooter 
*>(emitter->getShooter());
        shooter->setThetaRange(-osg::PI_4/8.0, osg::PI_4/8.0 ); // radians, 
relative to Z axis.
        shooter->setInitialSpeedRange(0,20); // meters/second
        emitter->setShooter(shooter);
        osgParticle::ModularProgram *program = new osgParticle::ModularProgram;
        program->setParticleSystem(dustParticleSystem);
        scene->addChild(program);

        osgParticle::FluidFrictionOperator *airFriction = new 
osgParticle::FluidFrictionOperator;
        airFriction->setFluidToAir();
        airFriction->setWind(osg::Vec3(0.25, 0, 0));
        program->addOperator(airFriction);

        osgParticle::AccelOperator *accelUp = new osgParticle::AccelOperator;
        accelUp->setToGravity(-0.2f);
        program->addOperator(accelUp);

        osg::StateSet* stateset = dustParticleSystem->getOrCreateStateSet();
        stateset->setAttribute(program_data->particle_program);
        osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0);
        stateset->addUniform(baseTextureSampler);
        stateset->addUniform(patt);
    }
    osgParticle::RandomRateCounter *dustRate;
};



At the begining of every cycle I clean root this way.

Code:

  viewnode_mtx->removeChildren(0,viewnode_mtx->getNumChildren());



when I need to add particle system to scenery root I use.

Code:

  this->smoke_right = new SmokeParticleSystem(this->viewnode, 
this->pat_r.get(),this->point_att_u);
                this->smoke_right->setNodeMask(IS_VISIBLE_MASK);
                this->smoke_right->setName("smoke");
                this->viewnode_mtx->addChild( this->smoke_right);


  
Could you please comment if memory freed when I remove children or not. And 
maybe I should use ref_ptr on smokeparticlesystem. 
Thank you!
Cheers,
Roman

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54481#54481





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

Reply via email to