Instanced meshes + post process throws exceptions

Using either instanced meshes alone or ScreenSpaceCurvaturePostProcess without instanced meshes works fine for me. When I use them in combination, I get an exception thrown during render in GeometryBufferRenderer._createRenderTargets here:

                    let instanceDataStorage = (effectiveMesh as Mesh)._instanceDataStorage;

                    if (!instanceDataStorage.isFrozen &&
                        (material.backFaceCulling || material.overrideMaterialSideOrientation !== null)) {

With this code path, _instanceDataStorage is undefined.

My code is as follows:

import {
    Scene, Vector3, ArcRotateCamera, HemisphericLight, Mesh, MeshBuilder, Engine, SceneLoader,
    ScreenSpaceCurvaturePostProcess
} from 'babylonjs';
import 'babylonjs-loaders';

function createScene(canvas: HTMLCanvasElement, engine: Engine): Scene {
    const scene = new Scene(engine);

    const camera = new ArcRotateCamera(
        "camera", -Math.PI / 2, Math.PI / 2.5, 3, new Vector3(0, 0, 0), scene);
    camera.attachControl(canvas, true);

    const light = new HemisphericLight("light", new Vector3(0, 1, 0), scene);

    SceneLoader.ImportMeshAsync("", "", "tree.glb").then((result) => {
        const tree = result.meshes[0].getChildMeshes()[0] as Mesh;

        tree.isVisible = false;
        for (let z = 0; z < 30; z++) {
            for (let x = 0; x < 30; x++) {
                let inst = tree.createInstance("tree" + x + "_" + z);

                inst.position.x = 2 * x - 30;
                inst.position.z = 2 * z - 30;
            }
        }
    });

    const cavity = new ScreenSpaceCurvaturePostProcess("cavity", scene, 1, camera);

    return scene;
}

function makeBabylon(): void {
    const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
    const engine = new Engine(canvas, true);
    const scene = createScene(canvas, engine);

    engine.runRenderLoop(function() {
        scene.render();
    });

    window.addEventListener("resize", function() {
        engine.resize();
    });
}

makeBabylon();

Am I doing something wrong?

This is really hard to tell from this code :frowning: Could you repro the issue in the playground ? it would help us troubleshooting quicker as it definitely sounds like a Bug I would like to fix ASAP.

@Evgeni_Popov in case you have an idea ?

Sure, here is a repro of the issue in the playground: https://playground.babylonjs.com/#4AJ16M#248

1 Like

The fix should be up in 30 minutes

2 Likes

Built the latest from the git repo, and the fix works for me. Awesome!

Thanks for the quick fix.