pixijs / particle-emitter

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

TypeError: Cannot read property 'recycle' of null #141

Closed LukeWood closed 1 year ago

LukeWood commented 3 years ago

For some reason when creating many particle emitters I occasionally encounter this error.

This occurs inside of the Emitter.update method as the stack trace suggests.

Pixi-particles version: 4.3.0 pixi version: 5.3.3

index.js:1 TypeError: Cannot read property 'recycle' of null
    at Particle.kill (Particle.ts:378)
    at Particle.update (Particle.ts:264)
    at Emitter.update (Emitter.ts:858)
    at t (ParticleEmitter.tsx:62)
LukeWood commented 3 years ago

Some additional information:

The code causing this error is a react-pixi-fiber component: https://gist.github.com/LukeWood/3e2b40564be8f12690b2c8500c033de9

andrewstart commented 3 years ago

Hmm, Particle.emitter would only be null if the particle (and emitter) had been destroyed. That process should correctly clean everything up, and it looks like you have reasonable safeguards in place to not reuse a destroyed emitter, but my initial thoughts are that in spite of the safeguards somehow a destroyed emitter is being reused. You'd need to log out when things are destroyed, properties updated, and emitter updated to determine that.

LukeWood commented 3 years ago

Thanks for the quick reply.

Yeah - I’ve done a bit of logging but it’s a hard issue to repro only occurring once out of every 200~ emitters or so. I’ll be sure to post back here if I can find a definitive root cause.

LukeWood commented 3 years ago

One thing that DOES work in my checks is checking:

instance.emitter.emit before updating. Unfortunately this doesn’t play well with my playOnce particles.

LukeWood commented 1 year ago

( Outdated as this is maybe 10 versions old)