Particle system dispose leak with nested subEmitter

Playground

This relates to the abovementioned Playground code.
There is no leakage if you use the source code properly - https://playground.babylonjs.com/#X37LS1#86
(there was some in the past but it is corrected for some time now - Fix memory leak for particle sub emitter · BabylonJS/Babylon.js@1c97c9a · GitHub )

1 Like

Let me make it clear.
This function create a ParticleSystemSet, and then dispose it.
But the disposing can’t work properly, since after disposing, 2 ParticleSystem stay in the Scene.
This is because nested subEmitters haven’t been dispose correctly.

    function Firework(position)
    {
        // Create default particle systems
        var parentSystem = BABYLON.ParticleHelper.CreateDefault(position, 1);

        // Sub emitters
        function createFireworkSubEmitter(color, name) {
            var particleSystem1 = new BABYLON.ParticleSystem(name, 2000, scene);
            particleSystem1.particleTexture = new BABYLON.Texture("https://minio.cnbabylon.com/public/Assets/Flare.png", scene);
            particleSystem1.subEmitters = [[ createFireSubEmitter()],
                                            [createFireSubEmitter()]];
            var se = new BABYLON.SubEmitter(particleSystem1)
            return se;
        }

        function createFireSubEmitter() {
            var fireSubEmitter = new BABYLON.SubEmitter(new BABYLON.ParticleHelper.CreateDefault(position,200));
            fireSubEmitter.particleTexture = new BABYLON.Texture("https://minio.cnbabylon.com/public/Assets/Flare.png", scene);

            return fireSubEmitter;
        }
        parentSystem.subEmitters =[[createFireSubEmitter(new BABYLON.Color4(1, 0, 0), 0.4, 0.6, 2.4, 1),  createFireworkSubEmitter(new BABYLON.Color4(0, 1, 0, 1.0), "first")]]; //blendMode and the order subEmitters will effect the result
        parentSystem.start()

        parentSystem.dispose()
    }

So as far as I understand your question is how to dispose subemitters with parent system, am I correct?
As you see, both subemitters are not disposed and leave in the scene a transform node and a particle system.
image

That’s right.

Seems that particleSystem1 is just not disposed.

Here’s a little PR to fix this issue by making sure that the internal array _subEmitters has been created and populated when disposing. :slightly_smiling_face:

5 Likes

You rock!

1 Like