# WebGL error when toggling lights with freezed materials

**URL:** <https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724>\
**Category:** Bugs\
**Created:** [September 10, 2021, 9:39am UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724 "2021-09-10T09:39:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [September 10, 2021, 9:39am UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/1 "2021-09-10T09:39:58Z")

</div>

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](https://playground.babylonjs.com/#W6IZ0T)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 10, 2021, 1:43pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/2 "2021-09-10T13:43:54Z")

</div>

Are you using 4.2 or 5.0?

See:

> [@Babylon 4.2 enabling spotlight gives webgl uniform error](https://forum.babylonjs.com/t/babylon-4-2-enabling-spotlight-gives-webgl-uniform-error/22642/2):
>
> That will be hard to help on this one, as we don’t do fixes of older Babylon versions. Have you tried with 5.0? I know we fixed some “It is undefined behaviour to use a uniform buffer that is too small” warnings, but I don’t remember if it applies to spotlights or not… Note also that if you get this warning only a single time (or a small number of times - meaning, the number of logs in the console log does not rise infinitely - or at least does not reach 250, which is I think the limit after w…

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [September 10, 2021, 1:48pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/3 "2021-09-10T13:48:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 10, 2021, 1:59pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/4 "2021-09-10T13:59:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 10, 2021, 2:44pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/5 "2021-09-10T14:44:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 10, 2021, 2:58pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/6 "2021-09-10T14:58:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 10, 2021, 3:32pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/7 "2021-09-10T15:32:00Z")

</div>

Yup makes sense, I am not seeing it either 🙂

---

<div class="post-metadata">

**Author:** ![ladevieq](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ladevieq/32/11077_2.png) [@ladevieq](https://forum.babylonjs.com/u/ladevieq)\
**Post date:** [September 15, 2021, 11:58am UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/8 "2021-09-15T11:58:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 15, 2021, 2:51pm UTC](https://forum.babylonjs.com/t/webgl-error-when-toggling-lights-with-freezed-materials/23724/9 "2021-09-15T14:51:21Z")

</div>

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