Skip to content

Conversation

@vincentfretin
Copy link
Contributor

@vincentfretin vincentfretin commented Dec 17, 2025

Description:

Previously, when an image failed to load (404), validateSrc in src-loader.js would fall back to treating the URL as a video, resulting in loadTexture returning a VideoTexture instead of indicating the error. (You got instead components: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:

  • Updating checkIsImage to check for common image extensions before doing a HEAD request
  • Updating loadTextureSource to reject the promise when resource is not found
  • Updating loadTexture to call cb(null) when source loading fails
  • Rejecting the promise in loadImageUrl when image request fails. Also fixed a typo in the error message format string ($s → %s).
  • Using .then(cb, onRejected) instead of .then(cb).catch(onRejected) to avoid catching errors thrown by the callback itself

PR done with the help of Claude Code with Opus 4.5

Comment on lines 150 to 152
checkIsImageFallback(src, onResult);
// Non-success status (404, etc.) - resource not found.
onResult(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage it's too early to conclude the resource would fail loading, as the status code might be in the 3XX range (redirects) or the server might not support HEAD requests (405). In those cases its still possible to load the image through the image tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I made changes.

Copy link
Contributor Author

@vincentfretin vincentfretin Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change was also wrong, assuming an error loading via the image tag meant not found. I reverted all that and instead check for common image extensions before doing a HEAD request. I had a similar patch in an aframe 1.6.0 project to not spam the server with HEAD requests because I used different images urls on a plane at regular interval like a slideshow.
Now the promise rejection happens on the ImageLoader error callback.

@dmarcos dmarcos merged commit be93909 into aframevr:master Dec 18, 2025
1 check passed
@vincentfretin vincentfretin deleted the fix-texture-load-failed branch December 18, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants