Dispose mesh by name

oddness in line 52 - 58

for (let i = 0; i < scene.meshes.length; i++) {
            let mesh = scene.meshes[i];
            if (mesh.name.endsWith("_merged")) {
                scene.meshes.splice(i, 1);
                // mesh.dispose()

why does mesh.dispose() throw an error?

First: It is not a good idea to remove an item within a loop over the items. You should go from the last item backwards to index 0: for (let i=scene.meshes.length-1; i>=0; i–) …

Second: mesh.dispose() returns this error. I suppose you have to remove the Hawok body first before removing the mesh because they are connected together.

in the inspector they are not :confused:

decomment : mesh.dispose()

does it work for you?
it doesn’t on my end :thinking:

I would like to answer your question with the word from scene of Romeo and Juliet on the balcony (act 2, scene 2):


1 Like


Here is a working PG:

Errors in your PG:
redMat.diffuseColor = new BABYLON.Color3.Yellow(); delete new
the same at line 79

Delete this:
scene.meshes.splice(i, 1);

and this at line 41:

If you disable Havok, it will destroy the world (you know what I mean, don’t reveal this to Kim Jong :smiley: :smiley: :smiley: ) so you can’t safely dispose the mesh.

You can disable it after the mesh has been disposed.

Added async to your functions to init the Havok engine as the doc says.




LoL, good one. I won’t mention that I tried for 20min disposing of the body before disposing of the mesh :zipper_mouth_face:, thinking the same as @CodingCrusader…though it’s hard to dispose of something that no longer exists, isn’t it ? :face_with_hand_over_mouth: :sweat_smile:

1 Like

Yep :wink: Imagine if we live in a simulation and a coder makes a mistake an disables the physics engine and it will destroy the world… We are fucked :smiley:

Lucky us, it isn’t me coding the world :crazy_face: Humanity might still stand a chance after all :rofl:

1 Like

They backup often, I hope so :smiley:

Thank you SO much for looking into this and solving it @roland !
:slight_smile: :sunglasses:

1 Like

You are very welcome!