Ban LastCreatedScene

My team often faced bugs in our project, when someone forgets to pass scene to some constructor of babylon API with optional parameter, so we banned LastCreatedScene via

Object.defineProperty(EngineStore, "LastCreatedScene", {
    get: function () {
        throw new InvalidOperationError("Use EngineStore.LastCreatedScene is prohibited.");
    },
});

(note, we create multiple scenes here and there)

We are making major update and updating our babylon dependency.
And app fails at CubeTexture.CreateFromPrefilteredData, because at some point code executes EngineStore.LastCreatedScene?.offlineProvider, even though we pass scene to CreateFromPrefilteredData.

Any ideas how to make it smooth?

Can you point me where this happens in the code? I’ll be happy to fix it

1 Like

Maybe this playground will be enough for you

console will contain the stack trace (might need to wait for source maps)

if not, I will check in 10 hours and reply after :^)

This will partially fix it:

Use scene offlineprovider for cubecreation by deltakosh · Pull Request #17088 · BabylonJS/Babylon.js

But if your scene has no offlineProvider then it will still try to get it from the LastCreatedScene

Scratch that! I find a way. You should be good!