Loading custom particle system leads to "Maximum call stack size exceeded"

I create a custom particle system: https://playground.babylonjs.com/#GXTHL9#1, and I save it to a json file using codes like:

var mySet = BABYLON.ParticleHelper.ExportSet( [parentSystem] );
var serializedJson = JSON.stringify(mySet.serialize(true));
function download(content, fileName, contentType) {
var a = document.createElement(“a”);
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
download(serializedJson, ‘firework.json’, ‘application/json’);

Then I load it by

$.getJSON(“./flame.json”, (JsonFile) => {
var parentSystem = particleSetParse(JsonFile, scene);
console.log(parentSystem);
parentSystem.start();
})

However, loading this particle system leads to error:

I guess the reason is too many sub emitters?

Hello and welcome!
“Maximum call stack size exceeded” error usually means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.
The best way to prevent this error is to double-check your recursive functions.

Thx for quick response!
However, I didn’t use any recursive functions in my code. What I did is just loading a json file into a particle system, while this particle system has many sub emitter(you can check my playground above).

I am not able to repro any issue from your playground not sure how I can repro it ?

Hi sebavan,
In above playground, I create a firework particle system, and it works well.
For repro it, you can save this whole particle system into a json file, using codes like:

var mySet = BABYLON.ParticleHelper.ExportSet( [parentSystem] );
var serializedJson = JSON.stringify(mySet.serialize(true));
function download(content, fileName, contentType) {
var a = document.createElement(“a”);
var file = new Blob([content], {type: contentType});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
download(serializedJson, ‘firework.json’, ‘application/json’);

Then you will get a json file from your browser.

Create a new scene, and load this json file into a particle system by:

$.getJSON(“./flame.json”, (JsonFile) => {
var parentSystem = particleSetParse(JsonFile, scene);
console.log(parentSystem);
parentSystem.start();
})

After loading this particle system, you can repro this error.

Ok so this playground can repro by pressing space if smdy else wants to have a look :slight_smile: https://playground.babylonjs.com/#GXTHL9#7

1 Like

The main issue is fixed here: Prevent subemitter dispose to overflow. by sebavan · Pull Request #10451 · BabylonJS/Babylon.js · GitHub and should soon be available in a nightly.

But please not that if you use ParticleSystemSet you should use a special folder hierarchy with all the textures in the textures folder and change ParticleSystemSet.BaseAssetsUrl to be the root of all your deps.

In your case (having only one system) it is easier to serialize parse it directly: https://playground.babylonjs.com/#GXTHL9#8

3 Likes