convertToFlatShadedMesh() errors fatally after updatable=false but not after updatable=false

in case there are less colors than positions/vertices.
Just a quick note, I will provide PG.
This is not unreasonable but surprising. Probably the error should be handled gracefully somehow ?

error after creating customMesh with updatable=true

no error after updatable=false

This may be the intended behavior but it took time to figure out that an updatable mesh insists on the correct number of vertex colors.

The mesh is not valid, so convertToFlatShadedMesh can’t work.

You have an error in the console log when trying to display the original mesh:

Babylon.js does not generally check the inputs (for perf reason), you are expected to provide valid data.

It works with “updatable=false” only by side effect I think, you should really provide as many data as the number of vertices.


Thanks. It is reasonable to expect valid inputs. It was the inconsistency which took time to discover.

1 Like

Since I looked it up let me just make a note here that

appears to be where the error occurs. The problem is that there already exists a color buffer which is too short for count which is based on the number of vertices. So count could be limited by the source buffer size to avoid the error but that may not make much sense and provoke other errors later.
There seem to be some guards against bad input data but due to back compat. I guess they cannot be removed anymore.

My use case was that I wanted to apply the possibly short colors as a default, and then later modify them if necessary, for example after conversion to flat shaded.

Hm, 4.2 does not have the error in the playground.