WebGL error when toggling lights with freezed materials

Hello BabylonJS team.

I encounter a WebGL error (It is undefined behaviour to use a uniform buffer that is too small) when toggling lights on a scene with freezed materials.

I tried to unfreeze materials before toggling a light and it doesn’t throw any errors.

Here is a repro
https://playground.babylonjs.com/#W6IZ0T

Are you using 4.2 or 5.0?

See:

I’m using Babylon 4.2, but i encounter the error with Babylon 5.0 too

I think it’s expected (pinging @sebavan/@Deltakosh):

When freezing a material, the current state is “frozen” and especially the lights that were in effect at freezing time. If later on you modify the set of lights that are in effect, it will crash (as you experienced it). The workaround is to do what you did: unfreeze the materials, modify the lights, freeze the materials again.

Yup totally expected but I wonder how we could make it more obvious “console.err” something ?

I don’t see an easy way to console.log something.

We would need to record the whole state at freezing time (maybe there are other things than the lights that may break) and compare the current state with the frozen state each time we have to draw something… Not very easy and efficient I think.

Yup makes sense, I am not seeing it either :slight_smile:

I just noticed something else, the problem isn’t present if i use two directional light instead of a directional light + an hemispheric light.

Yup cause they are using the exact same uniform layout :slight_smile: so it is a lucky shot