# App that worked for months (using NME materials) suddenly hangs with shader errors

**URL:** <https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441>\
**Category:** Bugs\
**Created:** [July 14, 2023, 4:41pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441 "2023-07-14T16:41:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hrvoje\_Cop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hrvoje_cop/32/33635_2.png) [@Hrvoje\_Cop](https://forum.babylonjs.com/u/Hrvoje_Cop)\
**Post date:** [July 14, 2023, 4:41pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/1 "2023-07-14T16:41:08Z")

</div>

Hi!

I have a product configurator built with babylon and React. It’s been deployed live months ago and worked flawlessly. Sometime in the last few days something happened and now it hangs with fragment shader errors. The browser points me to the following line:

o.logFunc && o.logFunc("BJS - " + r); (which I now realize is only the logging function…)

And it says the error is in line 217 or 218 in the fragment shader code:

vec3 perturbNormalBase(mat3 cotangentFrame,vec3 normal,float scale)

We are using custom materials made with the node editor so my guess is that something there is at fault, but like I said, it worked normally on all platforms for months up until trying it today. So I guess something must have changed in the last update.

You can find the configurator here:

> **[Frame Sideboard | Milla & Milli](https://millamilli.com/frame-sideboard.html)**
>
> Milla&Milli is a celebration of design, a proclamation of love and an ode to Mother Nature, all joined together into astonishing pieces of solid wood furniture.

Now our client’s configurator is dead in the water so I would beyond grateful for any help I can get here ASAP.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 14, 2023, 4:54pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/2 "2023-07-14T16:54:08Z")

</div>

Hello! What version of Babylon are you using? Tagging @Evgeni_Popov here to take a look as he’s our shader expert

---

<div class="post-metadata">

**Author:** ![Hrvoje\_Cop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hrvoje_cop/32/33635_2.png) [@Hrvoje\_Cop](https://forum.babylonjs.com/u/Hrvoje_Cop)\
**Post date:** [July 14, 2023, 4:58pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/3 "2023-07-14T16:58:15Z")

</div>

This one loads babylon from CDN so the latest, thus whatever changed between the last two builds I guess broke this.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 14, 2023, 5:09pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/4 "2023-07-14T17:09:28Z")

</div>

First of all you should NEVER have a production project pointing to our live version CDN  
You must point to a stable number that you have tested and validated:  
[babylonjs - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers](https://cdnjs.com/libraries/babylonjs)

So I guess the most urgent for you is to publish an update of your site pointing to a working version

Then do you mind sharing a PG with the actual problem so we can help debugging?

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [July 14, 2023, 5:13pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/5 "2023-07-14T17:13:46Z")

</div>

> [@Deltakosh](#):
>
> First of all you should NEVER have a production project pointing to our live version CDN  
> You must point to a stable number that you have tested and validated:

Just elaborating a bit on this, the latest CDN is updated weekly, and through we try our best to validate the changes aren’t breaking anything (we have a testing infrastructure that runs on every PR), sometimes things will slip by undetected in the tests, especially in more specific cases, so in production, it’s safer to point at a constant version and validate before updating.

---

<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:** [July 14, 2023, 5:19pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/6 "2023-07-14T17:19:49Z")

</div>

I think 99% that the problem comes from :

> <https://github.com/BabylonJS/Babylon.js/pull/13935>
>
> I notices that \`set lines\` takes 19.29ms for 68 calls while my scene initializai…on, so I add some checks to avoid process heavy operations like \`trim\` and \`split\` on the string. As a result, in my case this function take 9.45ms for same 68 calls. And it still works as before, of course, but faster :)
> 
> P.S. Results of my measurements:
> \`\`\`
> default:
> 
> {count: 68, avg: 0.342647, max: 1.500000, allTime: 23.299999}
> {count: 68, avg: 0.267647, max: 1.300000, allTime: 18.199999}
> {count: 68, avg: 0.282352, max: 1.299999, allTime: 19.200000}
> {count: 68, avg: 0.294117, max: 1.200000, allTime: 19.999999}
> {count: 68, avg: 0.330882, max: 1.700000, allTime: 22.500000}
> {count: 68, avg: 0.326470, max: 4.500000, allTime: 22.199999}
> {count: 68, avg: 0.276470, max: 1.100000, allTime: 18.799998}
> {count: 68, avg: 0.255882, max: 0.799999, allTime: 17.400000}
> {count: 68, avg: 0.263235, max: 1.200000, allTime: 17.900000}
> {count: 68, avg: 0.260294, max: 0.899999, allTime: 17.699999}
> {count: 68, avg: 0.269117, max: 1.000000, allTime: 18.299999}
> {count: 68, avg: 0.280882, max: 1.099999, allTime: 19.099999}
> {count: 68, avg: 0.260294, max: 0.900000, allTime: 17.700000}
> {count: 68, avg: 0.263235, max: 0.900000, allTime: 17.899999}
> 
> avg allTime: 19.29ms
> 
> \-------------------------------------------------------------
> 
> after optimization:
> 
> {count: 68, avg: 0.195588, max: 3.000000, allTime: 13.299999}
> {count: 68, avg: 0.138235, max: 1.000000, allTime: 9.399999}
> {count: 68, avg: 0.180882, max: 2.000000, allTime: 12.300000}
> {count: 68, avg: 0.155882, max: 1.400000, allTime: 10.600000}
> {count: 68, avg: 0.151470, max: 0.900000, allTime: 10.299999}
> {count: 68, avg: 0.145588, max: 1.599999, allTime: 9.899999}
> {count: 68, avg: 0.120588, max: 0.699999, allTime: 8.199999}
> {count: 68, avg: 0.122058, max: 0.700000, allTime: 8.299999}
> {count: 68, avg: 0.117647, max: 0.700000, allTime: 8.000000}
> {count: 68, avg: 0.123529, max: 0.799999, allTime: 8.400000}
> {count: 68, avg: 0.135294, max: 0.800000, allTime: 9.200000}
> {count: 68, avg: 0.141176, max: 0.700000, allTime: 9.600000}
> {count: 68, avg: 0.138235, max: 1.000000, allTime: 9.400000}
> {count: 68, avg: 0.133823, max: 0.799999, allTime: 9.099999}
> {count: 68, avg: 0.117647, max: 0.600000, allTime: 8.000000}
> {count: 68, avg: 0.150000, max: 1.899999, allTime: 10.200000}
> {count: 68, avg: 0.114705, max: 0.900000, allTime: 7.799999}
> {count: 68, avg: 0.135294, max: 0.700000, allTime: 9.199999}
> {count: 68, avg: 0.123529, max: 0.700000, allTime: 8.399999}
> {count: 68, avg: 0.138235, max: 0.699999, allTime: 9.400000}
> 
> avg allTime: 9.45ms
> \`\`\`

because there’s a flying “;” between the end of one function and the start of the next.

I think only the latest versions 6.12.1 and 6.12.0 have this problem, so if you take any version before or equal to 6.11.2, it should be fine.

If possible, @Hrvoje_Cop, can you share your code, even privately? We did a number of tests with this PR and everything was fine, but we seem to have missed something ([EDIT] There’s also the option that the problem does not come from this PR)…

---

<div class="post-metadata">

**Author:** ![Hrvoje\_Cop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/hrvoje_cop/32/33635_2.png) [@Hrvoje\_Cop](https://forum.babylonjs.com/u/Hrvoje_Cop)\
**Post date:** [July 14, 2023, 5:46pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/7 "2023-07-14T17:46:22Z")

</div>

> [@Deltakosh](#):
>
> First of all you should NEVER have a production project pointing to our live version CDN  
> You must point to a stable number that you have tested and validated:  
> [babylonjs - Libraries - cdnjs - The #1 free and open source CDN built to make life easier for developers](https://cdnjs.com/libraries/babylonjs)
> 
> So I guess the most urgent for you is to publish an update of your site pointing to a working version
> 
> Then do you mind sharing a PG with the actual problem so we can help debugging?

Despite being apparently able to make a fully featured configurator app, this app was my very first contact with JS ever, let alone babylon and react. So a very, very noob mistake on my part. Damn… I really should have thought of that. 🤬

I can find the babylon.js with the appropriate version (in our case one that I know works is 5.32.1).  
Can I use the loaders module from:  
[https://cdn.jsdelivr.net/npm/babylonjs-loaders@5.32.1/babylonjs.loaders.min.js](https://cdn.jsdelivr.net/npm/babylonjs-loaders@5.32.1/babylonjs.loaders.min.js)

Or is there a more recommended source?

I’ve just tested loading the appropriate version from these two links and everything works properly.  
So all that’s necessary to fix this is to replace these two lines on all the pages, not the worst thing ever thankfully, we don’t have to rebuild or anything. Thanks for the quick answers guys, much appreciated.

> [@Evgeni\_Popov](#):
>
> If possible, @Hrvoje_Cop, can you share your code, even privately? We did a number of tests with this PR and everything was fine, but we seem to have missed something ([EDIT] There’s also the option that the problem does not come from this PR)…

The problem is not in my code though, it comes from the node materials I’m using, which I just confirmed by trying to load one in the node editor, and getting the very same error. You can find an example here:

> **[Babylon.js Node Material Editor](https://nodematerial-editor.babylonjs.com/#KHZXYR)**
>
> Babylon.js Node material editor - shader-based materials editor for Babylon.js

> [@Evgeni\_Popov](#):
>
> I think only the latest versions 6.12.1 and 6.12.0 have this problem, so if you take any version before or equal to 6.11.2, it should be fine.

Tested this as well just now, and yes, 6.11.2 works as well.

---

<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:** [July 14, 2023, 6:08pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/8 "2023-07-14T18:08:37Z")

</div>

Great, thanks for the repro in the NME!

---

<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:** [July 14, 2023, 6:28pm UTC](https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials-suddenly-hangs-with-shader-errors/42441/9 "2023-07-14T18:28:29Z")

</div>

The problem will be fixed by:

> <https://github.com/BabylonJS/Babylon.js/pull/14049>
>
> See https://forum.babylonjs.com/t/app-that-worked-for-months-using-nme-materials…-suddenly-hangs-with-shader-errors/42441/8
> 
> The problem is a bug in \`PerturbNormal\` (that does not remove a ";" in some injected shader code), but which was hidden by the way we parsed the shader code before #13935.
