Open stingray21 opened 8 months ago
A library like this might help: https://github.com/bvaughn/react-error-boundary
You can't put hooks in try/catch blocks (https://github.com/facebook/react/issues/16026) so I wouldn't expect useTexture
to do anything about that, but as ^ implied you can catch it with ErrorBoundary (nice lib here) and attempt to pass a fallback texture or do whatever else you imagined inside catch before resetting the EB render.
Thank you for contributing! We’re marking this issue as stale as a gentle reminder to revisit it and give it the attention it needs to move forward.
Any activity, like adding an update or comment, will automatically remove the stale label so it stays on our radar.
Feel free to reach out on Discord if you need support or feedback from the community. This issue will close automatically soon if there’s no further activity. Thank you for understanding and for being part of the project!
three
version: 0.161.0@react-three/fiber
version: 8.15.16@react-three/drei
version: 9.97.6node
version: 18.19.1npm
version: 10.2.4Problem description:
I'm using @react-three/fiber's useTexture to generate a decal for a three.js object.
The url for the image file (
fileName
) gets generated dynamically and the image files live on a different serverThis works fine as long as the file exists. However, I get a runtime error, if the file is not valid.
I cannot figure out how to catch/mitigate that error.
Relevant code:
Here is a minimal working code sample: https://codesandbox.io/p/sandbox/adoring-dijkstra-mz2hsy
Suggested solution:
I already tried to wrap it in a
try/catch
but that never loads the decal, even if the image file exists and causes a never ending amount of this error:
And this version (using an empty image in
catch
)causes this error:
Seems like this drei issue is related, but I couldn't fix my problem that way (
ErrorBoundary
) either.When I use
TextureLoader
instead ofuseTexture
, i.e.then there is just no texture with the faulty url and I get this error in the console:
but the site does not crash completely.