Jump to content

When is it safe to freeze materials?


Recommended Posts


I had some transparent textures that broke when updating to the current nightly build (from 3.2). After much searching, the problem seems to depend on the timing of when I call "mat.freeze()". Can someone confirm if this is a bug or not?

Specifics: in my project I create and set up my materials and textures at init, and then freeze the material. I delay the "freeze" call, to give Babylon a chance to initialize, but this is while the game is paused so no renders are taking place.

var mat = new BABYLON.StandardMaterial(name, scene)
// set some colors...

var tex = new BABYLON.Texture(url, scene, noMip, true, sampling)
tex.hasAlpha = true
mat.diffuseTexture = tex

// freeze material after a tick
setTimeout($ => { mat.freeze() }, 10)

In 3.2 this worked fine, but in 3.3 my transparent textures are broken. If I delay calling "mat.freeze()" until after the scene has rendered at least once, things work as in 3.3.

Bug or no? When is it safe to freeze materials?


Link to comment
Share on other sites

I can't easily reproduce this in the PG, as it seems to depend on the timing of when scene.render is called.

11 hours ago, Deltakosh said:

As a rule of thumb, freezing is valid when mat.isReady() is true

This looks promising, but mat.isReady() is never true - it returns false if no mesh argument is passed in.

Do I need to check isReady(mesh) for a mesh the material is used for? Or all of them?

Link to comment
Share on other sites

Hi, thanks for the response but it seems that things are more complicated than that.

I managed to make a PG that (probably?) replicates my issue:


As you can see it creates a bunch of meshes, which all use the same material, and then freezes the material later on. The meshes become visible at various delays. The transparent texture breaks for some meshes, but not always the same ones - it seems to depend on whether or not the mesh has been rendered at the time when mat.freeze() is called?


Link to comment
Share on other sites

5 hours ago, Deltakosh said:

This is expected. The mesh has to be rendered once before you can actually freeze the mat

Per the PG, isReady(mesh) returns true even for meshes that haven't rendered yet.

Does that mean it's impossible to tell whether it's safe to freeze a material that is being used for multiple meshes?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...