pixijs / particle-emitter

A particle system for PixiJS
http://pixijs.io/particle-emitter/docs
MIT License
784 stars 124 forks source link

The particle emitter can encounter undefined particles which casues it to choke and break #181

Closed aaclayton closed 1 year ago

aaclayton commented 1 year ago

Using version 5.0.7"

I'm afraid I don't have a clean reproduction case for this, but my situation is that I sometimes destroy and remove a particle emitter and construct a new one. At times during this process when a new emitter is first constructed, it can encounter an update loop in the ticker where some particle is undefined. I don't know why the particle is undefined, but the issue shows up starting in the following loop:

for (let particle = this._activeParticlesFirst, next; particle; particle = next)
{

in cases that particle is undefined - the loop eventually crashes at:

if (this.updateBehaviors[i].updateParticle(particle, delta))

image

Sorry this isn't much to go on, I hope you might have a theory upon seeing this report. Let me know if I can provide any further detail that would be helpful.

andrewstart commented 1 year ago

So it isn't particle that is null, but particle.transform (inside the particle.scale getter), due to the particle having been destroyed (normally inside destroying the emitter). Because Emitter.destroy() pretty thoroughly clears both the particle references and the behaviors that would allow Emitter.update() to do anything when it runs, it seems that somehow a particle that belongs to a running emitter is getting destroyed rather than a destroyed emitter continuing to run. The other possibility of a destroyed particle finding its way to a new emitter seems less likely, as Emitters do not pool particles at all.

I hope this gives you enough direction to look for a cause within your code. I'm not completely ruling out a bug in the library in some rare condition, but if that is the case it isn't something that I can suss out without a running example.

aaclayton commented 1 year ago

Thanks @andrewstart - I'll look into it and see if I can figure out some sort of repro case. I am certainly not doing anything to call destroy on individual particles, I only ever destroy the emitter itself.

aaclayton commented 1 year ago

Hi @andrewstart I was able to identify the problem and resolve it. I was toggling off the emit property for each emitter and later destroying them - but there was a timing issue where I was calling ParticleEmitter#destroy after a parent PIXI container was called with destroy({children: true}). Sorry for the false alarm.