Uncaught TypeError: subMesh.getBoundingInfo() is undefined

Hi There,

I’m updating some projects to 5.1, and I’m not getting any errors in the code editor but the console is showing:

Uncaught TypeError: subMesh.getBoundingInfo() is undefined

_RenderSorted webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:200
_renderTransparentSorted webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:183
render webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:148
render webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingManager.js?:95
_renderForCamera webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3554
_processSubCameras webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3577
render webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3845
App webpack://primed-map/./src/app.tsx?:194
_renderFrame webpack://primed-map/./node_modules/@babylonjs/core/Engines/engine.js?:933
_renderLoop webpack://primed-map/./node_modules/@babylonjs/core/Engines/engine.js?:948
[common.bundle.js line 8857 > eval:200:121](http://127.0.0.1:5500/dist/common.bundle.js line 8857 > eval)
_RenderSorted webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:200
_renderTransparentSorted webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:183
render webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingGroup.js?:148
render webpack://primed-map/./node_modules/@babylonjs/core/Rendering/renderingManager.js?:95
_renderForCamera webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3554
_processSubCameras webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3577
render webpack://primed-map/./node_modules/@babylonjs/core/scene.js?:3845
App webpack://primed-map/./src/app.tsx?:194
_renderFrame webpack://primed-map/./node_modules/@babylonjs/core/Engines/engine.js?:933
_renderLoop webpack://primed-map/./node_modules/@babylonjs/core/Engines/engine.js?:948
self-hosted:1115

Any thoughts?

Even though I’m not getting a console log verifying it, I believe it has to do with how I’m creating LiDAR terrain with MeshBuilder, as when I exclude the LiDAR tiles I don’t get the error. MeshBuilder worked with version 4.2.2 but doesn’t seem compatible with 5.1.

We will need a repro as usual to help :slight_smile:

I think I’m on to something, and now that I’ve narrowed it down I’ll try reconstructing it in the playground. Here’s my train of thought:

It’s hard to diagnose the problem because the Web App worked with previous versions of BabylonJS, and now all of a sudden crashes within seconds of loading with the Uncaught TypeError: subMesh.getBoundingInfo() is undefined message and doesn’t highlight a particular line of my code (even in WebPack developer mode).

However, I did disable a “clean cache” feature in my LiDAR class that calls scene.clearCachedVertexData(); & scene.cleanCachedTextureBuffer(); when tiles are being disposed – and that seemed to fix it!

I’m going to investigate further, as like I said before it worked not that long ago and kept the JS Heap Size wayyy down as LiDAR tiles where built and disposed dynamically.

1 Like

I’m still not exactly sure how scene.clearCachedVertexData(); & scene.cleanCachedTextureBuffer(); inside my LiDAR class was breaking the render engine, but removing them and placing them in a higher level in the code seemed to fix it.

1 Like

I spoke too soon. The crash is sporadic…

From the callstack, you could try calling into _updateBoundingInfo on each mesh before clearing the caches ?

Unfortunately, it didn’t work. Here was my implementation based on your suggestion:

    // intermittently clean cache (this was taken from inside the LiDAR class *broke app for some reason*)
    setInterval(() => {
        scene.meshes.forEach((mesh, index) => {
            // eslint-disable-next-line no-underscore-dangle
            mesh._updateBoundingInfo();

            if (index === scene.meshes.length - 1) {
                scene.cleanCachedTextureBuffer();
                scene.clearCachedVertexData();
            }
        });
    }, 1500);

I can’t seem to reproduce the error inside of the playground, hence why I haven’t sent an example. Not clearing vertex and texture caches fixes the error but bloats the heap after a little while, so I’m in a bit of a pickle…

setInterval will do it several time and _updateBoundingInfo will need the data cleared on the first tick I believe, this should happen only once per mesh when the datas are present.

I tried to help reproduce too and found calling createDefaultEnvironment and then calling clearCachedVertexData leads to a runtime error.

And also tried the fix calling _updateBoundingInfo on each mesh first but still the same error.

You could try smthg like this instead: https://playground.babylonjs.com/#4VZFPX#2

as we need to keep track of positions and indices for bounding boxes picking and such.

1 Like

The reason I was using a setInterval in the code above was because the LiDAR class is basically a quadtree that subdivides a LiDAR tile as you zoom in, dynamically creating all this new geometry which gets stored in the heap – so when I removed that class method that triggered the cleanup automatically, I just called scene.cleanCachedVertexData every 1500 milliseconds in a much higher level part of the program for the time being.

Your most recent playground example worked, so I put it back in the LiDAR class and cleaned vertex data on newly created geometry, but unfortunately it pales in comparison to the old method (which still works with Babylon.js v5.0.0-alpha.63)

Old method:

New method:

I ll check if you could somehow lock the bounding box to prevent the crash despite not having any cpu data but without a fully specialized case for it.

Sounds good. All meshes have the pickable feature disabled; Im not doing any physics calculations, just seeing what the distance is between the camera and mesh, which tells the program whether to subdivided or hide meshes. Cleaning the cache only gets turned off if I have to do that kind of stuff in controlled areas (which worked in 4.2)

As a proof of concept could you try this one ? https://playground.babylonjs.com/#4VZFPX#3

2 Likes

I’ll get back to you shortly :smiley:

1 Like

That works!!! It’s been re-implemented into the LiDAR class. Thanks for helping on this :slight_smile:

2 Likes

Shouldn’t this line check the return value of subMesh.getBoundingInfo() to prevent the error in the PG?

Not really :slight_smile: as we should always have one. The main issue is when we delete it we lose some of the global availablity of the bounding info, that we should retain. I am trying to see how we can improve this without a manual workaround.