Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give error msg when image fails to render #5156

Open
barries opened this issue Sep 24, 2024 · 1 comment
Open

Give error msg when image fails to render #5156

barries opened this issue Sep 24, 2024 · 1 comment
Labels
egui feature New feature or request

Comments

@barries
Copy link

barries commented Sep 24, 2024

Is your feature request related to a problem? Please describe.
When adding images to a new app, any misconfiguration, like missing egui_extras and images crates or features, not calling egui_extras::install_image_loaders(), shows only an inscrutable red warning icon in the GUI, and only if your app happens to be in a state that shows images.

Describe the solution you'd like

An error message indicating (a) that the image wasn't rendered, (b) which image wasn't rendered, and (c) why. A panic would be fine, though a crate feature converting the panic to an error message would probable help some people be more comfortable with this feature.

A runtime error would be very helpful, it requires you to visit every state of the app that renders an image to make sure they all display, ideally this would be a compile time error. However, not letting a detectably incorrect app run is why we're using rust in the first place :).

Describe alternatives you've considered
N/A

Additional context
N/A

@lucasmerlin
Copy link
Collaborator

I think in order for this to be a compile time error egui would need to be generic over the image loaders, I don't think that's feasible.
I think we could add a debug_assertion if we try to show an image and absolutely no image loader is installed, so it would panic in debug builds but not in release builds.
But we'd need to be careful which other errors we panic on, since image loading might fail for many different reasons which shouldn't cause the app to crash. I wouldn't want my app to crash if e.g. a network request fails or the user tries to open a file that doesn't exist, or a file format that isn't supported.

I think we could add a log::warn for all these cases though, which would help debugging the issue.

Finally, if you really want your app to panic if image loading fails, you could use Image::load_for_size to check the result before showing the image, and panic if there is an error. You could add a utility method like show_image(ui: &mut Ui, image: Image) that does this to get this behavior everywhere in your app.

@lucasmerlin lucasmerlin added feature New feature or request egui labels Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants