Scene not being disposed in Playground

I have not seen a direct answer via searching, so I figured I would post about it. My playground is not clearing/disposing scenes as I run the code.

I am using setInterval to demonstrate in this example, but this is prevalent in my other projects.Here is a PG. https://playground.babylonjs.com/#LXDBJ8#2

Use the debug console, run the code, and you will see that interval is ran equal to the number of times ran per second. The playground should clear the scene when run is pressed, correct? Or is the playground limited in this scope.

Example: Run scene once, debug message appears once per second. Run twice, debug appears 2 times a second since the last scene was not cleared / disposed.

Hello and welcome,

I don’t see any code that eliminates the scene.
To eliminate a scene you have to do scene.dispose();
The your code displays in the console a message every 1 seconds, there is no scene eliminated.

Is there a way to dispose the scene on Run? In the playground. A observable or other callback?

I believe the issue is that setInterval is tied to the browser window, not to the scene. You could add a callback so that when the scene is disposed, it calls clearInterval.

https://playground.babylonjs.com/#LXDBJ8#5

2 Likes