Event trigger when texture does not load?

Is there an event that I can watch for when a texture does not load (HTTP 404)?

1 Like

How are you loading the texture? The AssetManager loads assets async, and so you would have the promise rejection or catch handler you might use.

If you’re just doing new Texture(…) you might consider subscribing to the appropriate XHR event, as textures are loaded via an XHR call IIRC

1 Like

There is a onError callback on the texture constructor that you can use for this :slight_smile:

2 Likes

Or you could take that approach, which is much more simple, reasonable, and effective! :+1::grin:

2 Likes

I am loading the .babylon file which references many textures - I would like to know which ones fail.

1 Like

Unfortunately we do not support this at the moment :frowning: Would gladly accept a PR though ?

1 Like

Once the scene loads, can I iterate through all the textures to find out if any did not load?

static handleInvalidImages(scene:BABYLON.Scene){
    scene.textures.forEach((texture: BABYLON.BaseTexture)=>{
         // ❓ what do I do here, attach an event handler or check a value?
    });
}

You can check texture.loadingError and texture.errorObject

I’m not finding those properties in TypeScript.

This was added only a month ago so it is only available in preview.

so no way to check with BJS 4.2, right?

nope

is there any way to replace the default red and black checkerboard pattern?

You can set BABYLON.Tools.FallbackTexture = a base 64 endoded image as we do here:Babylon.js/tools.ts at master · BabylonJS/Babylon.js · GitHub

2 Likes