BaseTexture.WhenAllReady throws uncaught TypeError for CubeTexture

Sample code:

    this.environmentTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(
      this.props.environmentImageUrls[index],
      scene
    );


    BABYLON.CubeTexture.WhenAllReady([this.environmentTexture], ()=>{
      scene.environmentTexture = this.skyboxIsBackground ? this.environmentTexture : this.backgroundTexture;
      this.setSkybox(scene);
    });

The thrown error:

babylonjs.js:14404 Uncaught TypeError: Cannot read property 'add' of undefined
    at o (babylonjs.js:14404)
    at Function.e.WhenAllReady (babylonjs.js:14406)
    at eval (eval at <anonymous> (base_model_viewer.js:717), <anonymous>:1:21)
    at BaseModelViewer.setEnvironment (base_model_viewer.js:717)
    at BaseModelViewer.prepareEnvironment (base_model_viewer.js:190)
    at base_model_viewer.js:313

I believe the issue comes from this line in the definition of BaseTexture.WhenAllReady in baseTexture.ts:

var onLoadObservable = (texture as any).onLoadObservable as Observable<BaseTexture>;

Looking at the definition of BaseTexture (BaseTexture - Babylon.js Documentation), it looks like there is no onLoadObservable defined. onLoadObservable is defined for Texture (Texture - Babylon.js Documentation)

1 Like

Hello and welcome!!!

Can you repro in the PG?

Sure thing, here you go: https://www.babylonjs-playground.com/#UU7RQ#452

Will be fix in next nightly! Thanks for the report

1 Like