Skip to content

Don't panic on extensionless image paths in ImageLoader#25051

Closed
dreamersilly wants to merge 1 commit into
bevyengine:mainfrom
dreamersilly:image-loader-extensionless-panic
Closed

Don't panic on extensionless image paths in ImageLoader#25051
dreamersilly wants to merge 1 commit into
bevyengine:mainfrom
dreamersilly:image-loader-extensionless-panic

Conversation

@dreamersilly

Copy link
Copy Markdown

Objective

Loading an image whose path has no file extension panics the IO task pool:

thread 'IO Task Pool (0)' panicked at bevy_image/src/image_loader.rs:208:22:
called `Option::unwrap()` on a `None` value

The FromExtension arm calls .extension().unwrap().to_str().unwrap() on the asset path. Extensionless textures are common in the wild, for example FBX .fbm embedded texture folders written by Reallusion AccuRIG, which is how I hit this.

Solution

When the path has no extension (or a non unicode one), fall back to the existing Guess logic and sniff the format from the file contents. The guess code was already there in the arm below, so it moves into a shared helper. Guessing can still fail on genuinely unknown bytes, but that now surfaces as the loader's normal FileTextureError instead of a panic.

Testing

Reproduced on 0.19 and main with a PNG stripped of its extension: before, the panic above; after, the image loads. cargo test -p bevy_image passes.

The FromExtension setting unwrapped the asset path's extension, so loading
an image whose path has none panicked the IO task pool. Fall back to
guessing the format from the file contents (the existing Guess logic,
moved into a shared helper) and let a failed guess surface as the loader's
normal FileTextureError.
@github-actions

Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@dreamersilly
dreamersilly deleted the image-loader-extensionless-panic branch July 18, 2026 03:00
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.

1 participant