# Creation of texture using a URL which has already caused failure will not trigger onError handler

**URL:** <https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322>\
**Category:** Bugs\
**Created:** [October 5, 2021, 4:29pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322 "2021-10-05T16:29:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haoxin\_LIU](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/haoxin_liu/32/19001_2.png) [@Haoxin\_LIU](https://forum.babylonjs.com/u/Haoxin_LIU)\
**Post date:** [October 5, 2021, 4:29pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/1 "2021-10-05T16:29:47Z")

</div>

Repro in playground:  
[https://www.babylonjs-playground.com/#EL1XMF#1](https://www.babylonjs-playground.com/#EL1XMF#1)

When creating a Babylon texture by providing a image UR that would cause failure, most likely due to CORS policy, the first texture loaded will error out correctly so it can be handled accordingly by the client program. However if the same URL is used to create texture again, it would not trigger the onError handler since the \_getFromCache call would result in a hit and the texture will not be re-created, and the on error handler cannot run either.

In the playground the second texture will trigger success callback but in SharePoint spaces we are not able to see either handler to run.

I think the cache hit should not happen if the previous texture creation has failed, but due to a variety of async process during texture creation I am reporting this as a bug to the Babylon team to see what’s the expected behavior, when a URL would fail, but another texture need to be created before its callback.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 5, 2021, 4:47pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/2 "2021-10-05T16:47:27Z")

</div>

Keeping the texture in cache prevents extra errors when we are sure of the result but I agree it is less than convenient to catch errors ☹

@Deltakosh do you see any inconvenient to by passing the cache in case of error ? so that next load will generate an error as well ?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 5, 2021, 4:56pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/3 "2021-10-05T16:56:48Z")

</div>

Checked with @Deltakosh offline, I ll remove the cache when in error.

This will be in the next release.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 5, 2021, 6:36pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/4 "2021-10-05T18:36:55Z")

</div>

PR is here [Texture error when cached by sebavan · Pull Request #11217 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/pull/11217), it will be in the next nightly, I guess you want a new NPM @Haoxin_LIU ?

---

<div class="post-metadata">

**Author:** ![Haoxin\_LIU](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/haoxin_liu/32/19001_2.png) [@Haoxin\_LIU](https://forum.babylonjs.com/u/Haoxin_LIU)\
**Post date:** [October 5, 2021, 7:38pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/5 "2021-10-05T19:38:30Z")

</div>

@sebavan there is no rush we can wait for the next rollout. With this new fix, if a second entity tries to load the same url before the url is removed from cache, will it be able to have its error handler invoked?  
Basically, 2 images being loaded in the same scene at the same time, how can the second one know when to error out?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 5, 2021, 7:43pm UTC](https://forum.babylonjs.com/t/creation-of-texture-using-a-url-which-has-already-caused-failure-will-not-trigger-onerror-handler/24322/6 "2021-10-05T19:43:52Z")

</div>

Yup it is the point of the fix, in your test scene both textures will be notified of the same error through the cached internal texture 🙂
