Unable to dispose of clones more than once in for loop

I’ve been able to clone a mesh x amount of times (based on input value) but cannot dispose those clones when I try to decrease that input value more than once (demo here Babylon Example).

For some reason i can only dispose of the clones once in the for loop (i.e. I decrease input value from 5 to 4, 1 clone disappears, but when i try again to decrease from 4 to 3, nothing happens)

Not sure if this is a JS or Babylon issue though.


Would you mind creating a repro in the Playground instead?

Looks like you are creating multiple spheres in your loop on top of ones that already exist, so even though you are removing the disposed ones the other ones still exist.

Yup you were absolutely right! Adding “if clone doesn’t exist” seemed to fix it!

If anyone is curious - Babylon Example (mainly used CodePen because i wanted to add HTML elements, wasn’t sure how to do that on Playground).


1 Like