Return null from loadTexture when image fails to load instead of wrongly creating a VideoTexture #5781
+66
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Previously, when an image failed to load (404),
validateSrcinsrc-loader.jswould fall back to treating the URL as a video, resulting inloadTexturereturning aVideoTextureinstead of indicating the error. (You got insteadcomponents:texture:warn './rainbow.jpg' is not a valid video). This made it difficult for callers to detect failed image loads.Example in the community component media-image where I checked
texture.image.tagName === "VIDEO"to know if the image was not found:https://github.com/c-frame/aframe-gltf-model-plus/blob/6269b0499fcf497097d55375c4f10a70ae85d4c1/src/components/media-image.js#L68-L76
Changes proposed:
This change properly handles loading errors by:
checkIsImageto check for common image extensions before doing a HEAD requestloadTextureSourceto reject the promise when resource is not foundloadTextureto callcb(null)when source loading failsloadImageUrlwhen image request fails. Also fixed a typo in the error message format string ($s → %s)..then(cb, onRejected)instead of.then(cb).catch(onRejected)to avoid catching errors thrown by the callback itselfPR done with the help of Claude Code with Opus 4.5