Currently we can load a texture and check that it is valid with the observable: texture.onLoadObservable, but we cannot use an observable to check its loading failure.
technically you are using the wrong function, you should not use isReady to check for loading error.
isReady can be false after a successful texture load for a few frames due to it still being set up internally ( creating mipmaps and whatever else ) then it becomes true.
The correct function to use is isReadyOrNotBlocking
code looks like this :
/**
* Get if the texture is ready to be consumed (either it is ready or it is not blocking)
* @returns true if ready, not blocking or if there was an error loading the texture
*/
public isReadyOrNotBlocking(): boolean {
return !this.isBlocking || this.isReady() || this.loadingError;
}
The texture class does accept an error callback as one of the arguments :
In fact, it was in the case where the texture URL is bad, the texture does not load. So I wanted to display a color by default instead of a texture which fails.
But maybe my approach is not the right one. Hence my proposal to add a observable onError on a texture.
I suspected that isReady is not appropriate here, even though it seems to work.
The PG works. I commented on what I would like to do with an onErrorObservable and another comment where I use isReady which is less appropriate.
I know there is also an onError in the BABYLON.Texture constructor that can do this. But I told myself that this could perhaps also be done with an observable like for texture.onLoadObservable
It’s just an idea I’m proposing. I did this intuitively, thinking that we could do it (onErrorObservable like onLoadObservable), and I saw that this observable did not exist.
If you enter a url in the dialog this assigns a texture.
If we leave a string empty, this assigns a color.
If the URL is bad, capture the error and display a color instead of the texture.