Instanced mesh transformed only after 1-2 frames delay


Steps to reproduce:

  1. Create some mesh and disable it.
  2. After some time create an instance of that mesh and apply some position/scaling to that instance.
  3. Observe that the instance first appears “untransformed”, with position/scaling only being applied after a few frames.

Reproduces in desktop Chrome,
doesn’t reproduce in desktop Safari (weirdly).

Reproduces with BJS 5.x, but not with BJS 4.x

I’m not sure if that’s a bug or not, but different behaviour in browsers seemed suspicious to me.

Thank you!

Maybe @Cedric might have an idea of what’s going on?

My 1st guess is some buffers for instancing take a few frames to get from the code to the GPU.
Can you please provide a PG ?

sure, actually, the PG link is there in the original post (first line) :slight_smile:

1 Like

I’ve just tested that it doesn’t repro with bjs 4.2.1
Is there something that changed in the active meshes computation that can explain it @sebavan ?

Oh it might be related to a change which occurred a couple days ago @Deltakosh what do you think ?

Actually it is not really a bug :slight_smile:

This is because of parallel shader compilation. On chromium shaders can be compiled on a separated thread which is good for perf. While the shader is compile babylonjs allows you to keep using the previous shader if you want to.

Here you are adding instances later which means that babylonjs has to recompile a new shader to include support for instances. While the shader is rebuilt, the previous shader is used. But it is already fed with data for the instance rendering (which include a world matrix set to identity)

The best solution is simply to ask the shader to NOT do hot swapping:
Babylon.js Playground (

The other option would be to add the instances right away so the first compiled shader will have instances ready


I see, now it’s clear what’s going on there, thank you!

Will proceed with disabling hot swapping as a hotfix, as creating instances right away would not be that easy in my particular case :pray:

1 Like