Problem deleting meshes

Hi, I have created a basic scene in react and added a add/delete button to add more meshes; however; for some reason if I want to clear all meshes in the scene, the dispose function wont clear the last 2 meshes (I am sure I am doing something silly).
I am also able to reproduce this on the playground. If you open the link, you will see I am creating 4 spheres and then in a for loop trying to dispose them from the scene; however they dont get deleted. (what am I missing here ??)

https://playground.babylonjs.com/#RYCALU

1 Like

As you dispose the length of scene.meshes gets shorter and so the loop stops early. Use a while loop.

2 Likes

Yes, that was it; while loop works! – thanks