Jump to content

dispose of all meshes in a loop does not work


georage
 Share

Recommended Posts

http://www.babylonjs-playground.com/#PFCYT#1

This playground makes 9 meshes and tries to delete them all at once in a loop.

It does not work.

Am I missing something? I defeated the problem via this unholy function ...

function deleteAllMeshes(scene){
    var countMesh = 0;
      scene.meshes.forEach(function(m) {
          countMesh++;
          console.log(m.name);
          m.dispose();
      });
    console.log(countMesh + " meshes deleted");
    var x = countMeshes(scene);
    if(x > 0) { deleteAllMeshes(scene); }
}  

Here is the output of the unholy function proving only half of the meshes are deleted per function call.

Capture.JPG

Link to comment
Share on other sites

thanks! i appreciate your showing me the light. I guess I will have to change my functions to use your method, but in every case except disposing of meshes it seems to work with "scene.meshes.forEach"

Is there a reason why your method is more reliable?

Link to comment
Share on other sites

  • 1 year later...

Hi, 

Old topic but this helped me !

 However, is there a way to do this without "disposing" the ground, as it's a mesh too ?

Because I have a scene where I can create boxes and spheres thanks to 2 create buttons, and i'd like to press a clear button and have all my meshes deleted except my ground.

Thanks for your time

On 01/08/2016 at 7:12 PM, Temechon said:

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...