Hi Vladimir,

I have just done a code review and believe I now understand the issue
and your solution, both the bug and provided solution are a bit
esoteric in nature so my gut instinct it to look for a solution that
is clearer in function so that others who will come across in the code
in future want be left pondering the purpose of it and how it works.

It's a shame that ParticleSystem has a vector<Particle> that contains
the dead particles as it'd be easier to handle if it'd manage a
list<ref_ptr<Particle>> as this would avoid the need for maintaining
dead particles within a a list of active particles.  There a
performance reasons for wanting a std::vector<> though, and sometimes
performance just has to trump clarity and elegance of code.

I haven't yet hit upon the cleanest solution.  One thought I've had to
is to set the depth of dead particles so rather than being 0 are set
to FLT_MAX so that dead particles are always pushed to back of the
vector once it's sorted.  This will simplify the dead particle
collection to just have to look at the last particles.

Thoughts?
Robert.


On 16 April 2013 13:49, Chebaev Vladimir <[email protected]> wrote:
> Hi
> I found a bug in osgParticle::ParticleSystem. If _sortMode is not NO_SORT 
> then vector _particles is sorted by distance to camera. Stack _deadparts is 
> wrong after sorting. Pointers in this stack can point to alive particles.  
> This leads to the sudden disappearance of the particles and the growth of 
> vector _particles in long time.
> Dead particles are located at the beginning or end of the _particles after 
> sorting. I propose to repopulate _deadparts after sorting.
>
> I added the following code to ParticleSystem.cpp after sorting of _particles:
>
>             //Repopulate death stack
>             unsigned int deadPartsNumber = _deadparts.size();
>             if (deadPartsNumber)
>             {
>                 _deadparts = Death_stack();
>                 Particle* firstDeadParticle = _sortMode==SORT_FRONT_TO_BACK ? 
> &_particles[_particles.size() - deadPartsNumber] : &_particles[0];
>                 for (Particle* iParticle = firstDeadParticle; 
> iParticle<firstDeadParticle + deadPartsNumber; ++iParticle)
>                 {
>                     _deadparts.push(iParticle);
>                 }
>             }
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to