particle-emitter icon indicating copy to clipboard operation
particle-emitter copied to clipboard

TypeError: Cannot read property 'recycle' of null

Open LukeWood opened this issue 4 years ago • 4 comments

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 avatar Dec 31 '20 02:12 LukeWood

Some additional information:

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

LukeWood avatar Dec 31 '20 05:12 LukeWood

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.

andrewstart avatar Dec 31 '20 15:12 andrewstart

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 avatar Dec 31 '20 18:12 LukeWood

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 avatar Dec 31 '20 18:12 LukeWood

( Outdated as this is maybe 10 versions old)

LukeWood avatar Jun 11 '23 19:06 LukeWood