Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug + fix: IndexInActor not updated in solver after a particle kill
#1
Hi there!

I was doing some kind of fancy particle management when I came across a bug preventing me to delete the last particle of an emitter if another particle from the same emitter has been killed before. (Note: I've been killing it the "proper" way, setting its life to zero)
The bug was due to the fact that the IndexInActor field from the ParticleInActor class in the solver is not updated when a particle is killed by the Emitter. The consequence is that when deleting my 2nd particle, its IndexInActor still "pointed" to the particle I just killed before and was moved to inactive particles group at the end of the list.
I took a quick look and it seems that there's nowhere where IndexInActor is updated, so the fix boils down to doing it in KillParticle:

Code:
       public bool KillParticle(int index){

           if (activeParticleCount == 0 || index >= activeParticleCount) return false;

           // reduce amount of active particles:
           activeParticleCount--;
           active[activeParticleCount] = false;

           // swap solver particle indices:
           int temp = particleIndices[activeParticleCount];
           particleIndices[activeParticleCount] = particleIndices[index];
           particleIndices[index] = temp;
           // FIX BEGIN
           solver.particleToActor[particleIndices[index]].indexInActor = activeParticleCount;
           solver.particleToActor[temp].indexInActor = index;
           // FIX END

I tried it on my scene and if fixes the problem wonderfully!
I guess this was the intent of the existing swap in particleIndices above (cf the comment), but the change is not deep enough in the system for it to work correctly.
Unless the bug was due to me using the system in the wrong way, I guess it would be good to have this extra piece of logic integrated in the next release.

Cheers!
Reply


Messages In This Thread
Bug + fix: IndexInActor not updated in solver after a particle kill - by tooomg - 28-01-2018, 05:34 AM