Error Thrown When Clearing Mesh Geometry

I am getting an error when trying to clear mesh geometry data in the newest version of babylon.

I tried creating the same error in the playground but I could not get it working:

Here is the code for the custom mesh:

import { MeshSetData, VoxelMeshInterface } from "Meta/Render/Meshes/VoxelMesh.interface";
import { FluidMaterial } from "../../Materials/Fluid/FluidMaterial.js";

export const FluidMesh: VoxelMeshInterface = {
 pickable: false,
 checkCollisions: false,
 seralize: false,
 clearCachedGeometry: false,


 createTemplateMesh(scene: BABYLON.Scene) {
  const mesh = new BABYLON.Mesh("fluid", scene);
  mesh.isPickable = this.pickable;
  mesh.checkCollisions = this.checkCollisions;
  if(!this.checkCollisions) {
    mesh.doNotSyncBoundingInfo = true;
  }
  mesh.doNotSerialize = this.seralize;
  return mesh;
 },

 syncSettings(settings) {
  if (settings.meshes.pickable) {
   this.pickable = true;
  }
  if (settings.meshes.clearChachedGeometry) {
   this.clearCachedGeometry = true;
  }
  if (settings.meshes.checkFluidCollisions) {
   this.checkCollisions = true;
  }
  if (settings.meshes.seralize) {
   this.seralize = true;
  }
 },



 _applyVertexData(mesh: BABYLON.Mesh, data: MeshSetData) {
  mesh.unfreezeWorldMatrix();
  const chunkVertexData = new BABYLON.VertexData();
  chunkVertexData.positions = data.positionArray;
  chunkVertexData.indices = data.indiciesArray;
  chunkVertexData.normals = data.normalsArray;
  chunkVertexData.applyToMesh(mesh, false);
  mesh.setVerticesData("cuv3", data.uvArray, false, 3);
  mesh.setVerticesData("ocuv3", data.overlayUVArray, false, 4);
  mesh.setVerticesData("faceData", data.faceDataArray, false, 1);
  mesh.setVerticesData("rgbLightColors", data.RGBLightColorsArray, false, 4);
  mesh.setVerticesData("sunLightColors", data.sunLightColorsArray, false, 4);
  mesh.setVerticesData("colors", data.colorsArray, false, 4);
  if(this.clearCachedGeometry) {
    mesh.geometry?.clearCachedData();
  }
  mesh.freezeWorldMatrix();
 },

 async rebuildMeshGeometory(mesh, data) {
  this._applyVertexData(mesh,data);
  return mesh;
 },

 async createMeshGeometory(mesh, data) {
  mesh.material = FluidMaterial.getMaterial();
  this._applyVertexData(mesh,data);
  return mesh;
 },
};

Here is what the error says:
error

It only happens if I disable collision detecting which I do.
I tried disabling collisions on the scene also and that did not work.

This worked just fine a few updates ago and now it is broken.

Any help would be much appreciated.

Seems to be this line Babylon.js/renderingGroup.ts at c1ea82b3b6d613d3920540aa889ff6b544f75479 · BabylonJS/Babylon.js · GitHub @RaananW @sebavan have we done any recent changes to bounding info? :thinking:

1 Like

Can you share a project where it fails? will be important to see the exact point and the way it is built. it might be an es6 import issue (i.e. something’s missing)

So, I am just using the minified babylon.js version that comes with the code snapshot.
But if you want to see the error yourself you can download the repo for Divine Voxel Engine:

Then go into the electron folder and do this:

>cd electron
>npm install
>npm run start

Then go to the test world called “simple” and open up the console.
I just committed to the repo the error so you can try it out.

That’s very hard to debug, but from what I can see there seems to be a submesh that doesn’t have the bounding information set.

You are also running this in electron? And have commited 116 files in your last commit…

If you can reproduce this in a local project, minimizing any side code that might influence the scene, we will be able to help. But it’s rather hard digging into such a large project to find a bug like that

I am just confused how a custom built mesh could have a sub mesh?
The error is only thrown when updating.

Also, for that massive commit was just because I have not updated in a while and one of my tools copies the engine about 3 times in the repo.

But specifically the error is coming from this function:

 _applyVertexData(mesh: BABYLON.Mesh, data: MeshSetData) {
  mesh.unfreezeWorldMatrix();
  const chunkVertexData = new BABYLON.VertexData();
  chunkVertexData.positions = data.positionArray;
  chunkVertexData.indices = data.indiciesArray;
  chunkVertexData.normals = data.normalsArray;
  chunkVertexData.applyToMesh(mesh, false);
  mesh.setVerticesData("cuv3", data.uvArray, false, 3);
  mesh.setVerticesData("ocuv3", data.overlayUVArray, false, 4);
  mesh.setVerticesData("faceData", data.faceDataArray, false, 1);
  mesh.setVerticesData("rgbLightColors", data.RGBLightColorsArray, false, 4);
  mesh.setVerticesData("sunLightColors", data.sunLightColorsArray, false, 4);
  mesh.setVerticesData("colors", data.colorsArray, false, 4);
  if(this.clearCachedGeometry) {
    mesh.geometry?.clearCachedData();
  }
  mesh.freezeWorldMatrix();
 },

The only part of the engine that actually uses Babylon is all under the Render folder.

Every mesh has itself as a submesh, so might be this :thinking:

Well I check and every water mesh in the scene has one sub mesh.
But I figured out if I don’t do this.

 mesh.doNotSyncBoundingInfo = true;

No error is thrown.

I am just confused as to what has changed. But maybe the mesh needs the bounding info to by properly culled by the scene. But I don’t need the bounding info for collisions and all of that.

Hey this looks like the same issue from this thread → the playground in the solution post shows how to fix it by setting the bounding info for the existing meshes. It’s only needed if the mesh has been rendered thou and only for transparent meshes if I remember correctly. :slight_smile:

What version are you using ? and what was the latest working one ? so we can try to narrow the issue down ?

For example here I just changed your mesh’s visibility to 0.5 to reproduce the error.

And here the same solution from the old thread fixes the error on this repro as well. I would give that a try. :slight_smile:

2 Likes

Sorry I did not respond sooner. It my was birthday yesterday and was out and about.

The version I am using right now is 5.22.0.

I will have to try a few versions to see if which one was working before.

1 Like

Huh very interesting I did not consider it being tied to the meshes transparency.

But, hopefully the bug can be fixed but until then I can try to use this.
Thank you!

All right I found a version that works: 5.0.0. Or just the original release for Babylon 5.0.
At least as far as I can tell started breaking after 5.8.0.
Hopefully this helps.

Ok the @Blake s playground is the solution :slight_smile: Before, due to a caching issue things were working by luck :slight_smile:

@Blake @sebavan
All right cool we got it figured out.
I am making this as the solution cause I found a much simpler way to make this work:

   const bbInfo = customMesh.getBoundingInfo();
        if (customMesh.subMeshes) {
            for(const sm of customMesh.subMeshes) {
                sm.setBoundingInfo(bbInfo);
            }
        }

Thank you again everyone!

2 Likes