Merge a cloned mesh leeds into out of memory

The following simple code worked in “5.0.0-beta.11” but since “5.0.0-rc.0” and “5.0.0-rc.1” it crashed the browser totaly:

let meshArray = [];
let mainBox = BABYLON.MeshBuilder.CreateBox("MainBox", {width: 500, height: 1000, depth: 200});
for(var x= 0; x <10; x++){
  let cloneBox = mainBox.clone("Clone_"+x);
  cloneBox.position = new BABYLON.Vector3(0 + x*530, 0, 0);
  meshArray.push(cloneBox);
}
let mergedMesh = BABYLON.Mesh.MergeMeshes(meshArray, true, false, undefined, false, true);

I think this comes from the optimisation of the merge function some days ago.

Is this intended or a bug?

I made a demo in the playground (It takes a while bevor the error occures → out of memory):

This should have fixed it yesterday Prevent crash when merging cloned meshes by RaananW · Pull Request #12103 · BabylonJS/Babylon.js · GitHub

You can see the result here: Babylon.js Playground but use ctrl+f5 to hard refresh.

Thx for the quick fix but I see another problem after the fix: from the 10 cloned boxes are only 2 visible, the first and the last box :wink:

I made a demo:

Yup Let s see if @RaananW can quickly find it ?

Actually this has a big impact, I ll work on it ASAP should be fixed in a couple hours

1 Like

The fix is in PR it will be in the next nightly later tonight. fix clone by sebavan · Pull Request #12118 · BabylonJS/Babylon.js · GitHub

1 Like

Thanks a lot! … nice job

Sorry for being annoying, but I’m just trying to report bugs :wink:
The merge function still has an error:
If only 1 mesh is transferred to the merge array, then the position is no longer correct.
Example:

The top box has been moved 200 in the Z axis.
After merge, however, the mergeresult box has Z position = 0.

Maybe you could do a check and when only 1 mesh is in the array you give it straight back.

Actual I make this workaround:

if(mergeArray.length == 1){
    bufferedMesh = mergeArray[0].clone();
    bufferedMesh.bakeCurrentTransformIntoVertices();
    mergeArray[0].dispose();
}else{
    bufferedMesh = BABYLON.Mesh.MergeMeshes(mergeArray, true, false, null, false, true);
}

This is actually by design as merge mesh will also bake the current transform into the vertices info.

First, thx for looking into this bug that occured for me two weeks ago on the friday nightly update.
My new scene, heavily relying on merges of meshes and clones was not loading anymore since then.

The memory leach fix did do the job, sort of. The scene now loads again however I’m getting some weird artifacts in some cases. I’d like to stress out here that everything was working perfectly before with 5.0 and is also working perfectly with the current cdn version.

I’m not sure how to understand what’s going on. I believe it might be related to a second level merge of already merged meshes and instances.

Please take a look at the partly re-instated 5.0 preview of my project:
Project Motorcycle Alpha for preview 5.0a

As opposed to (cdn):
Project Motorcycle Alpha

May be take a focus on one of these merges obviously having an issue (name ‘suspensionrear’) in the nodes. There are more of these but, on the other hand, since just about everything in this scene is based on merged meshes and clones, and eventually re-merges, it’s kinda strange to see that this occurs only for some merges. Again, it was working perfectly as of friday two weeks ago. May be yours can explain (the ‘by-design’ part) or re-instate the ‘old’ behavior?

Thx and thx for the ghosts :dotted_line_face: bug fixes session, a brilliant idea and commitment. Cheers Guys, and have a great day:)

@RaananW could you have a look ? if not I ll try to check tomorrow

1 Like

Yeah, that seems a bit odd. Would you be able to provide the meshes generating the suspensionrear or the axis_rear_suspension? they seem to be mostly influenced by the issue.

I was trying to check the code, but it’s hard to debug in a minified environment ( i mean babylon. Your code is not minified :-))

Thx Raanan, and yes, indeed my code isn’t minified at this point… it’s not even optimized;)
Yes, I can try to isolate these meshes and parts of the object constructor and share it with you (although you may have noticed the bug also occurs elsewhere, but not everywhere;)
I’ll be back and meanwhile, thx for your time looking into this…

1 Like

yep. I assume it is related to the same issue, so any simpler reproduction will help us pinpoint the issue.

Thanks a lot!!

1 Like

on it…just give me a few hours…i have some domestic disturbance to attend to;)

2 Likes

@RaananW thanks a lot !!!

Ok, having quickly done part of the work (isolating the meshes used in this part and just the clones and merges for this part of suspension), I can say I expected just about everything except this:

Project Motorcycle Debug merges

Works perfectly. So, I guess I now have to work it up, re-parenting this part to its parent (the frame) and see what happens next… Keep you posted…

Ok, going to the second level debug, I’m getting more and more confused about what’s happening.
Re-instated the frame parent object and parented my merges to the object and is still working perfectly as shown here:

Project Motorcycle Debug merges

The story goes on…

2 Likes