Skip to content

IMG.c: Loader now keeps trying other formats, if other supported format(s) failed to load an image #555

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Retro52
Copy link

@Retro52 Retro52 commented May 12, 2025

Hi

This PR makes IMG.c keep trying to load an image if another format fails.

The reason I even had this problem comes from trying to load this WebP image on iOS (I could not attach it to PR as GitHub does not support this format)

For some reason, this image was recognized as a TIF format image by the UTTypeConformsTo. I tried replacing it with the UTTypeEqual, but got the same result. The image load was failing because the TIF format check was performed before checking against WEBP.

While the problem I had is likely some rare edge case, I believe it would still be a good thing to try to handle such rare hiccups.

@Retro52 Retro52 force-pushed the ao/img-fallback branch from 1ff5ac1 to a946f92 Compare May 12, 2025 13:30
@slouken
Copy link
Collaborator

slouken commented May 12, 2025

This means that if we fail to load an image the error will always be "Unsupported image format" and we lose any informative error set by the loader.

@slouken
Copy link
Collaborator

slouken commented May 12, 2025

The TIFF image format is well defined, I'm not sure why this RIFF/WEBP image would be detected as TIFF.

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

The TIFF image format is well defined, I'm not sure why this RIFF/WEBP image would be detected as TIFF.

I suspect that the image is, maybe, too small, but that's not the bug that SDL could fix.

@slouken
Copy link
Collaborator

slouken commented May 12, 2025

We could also move TIFF to the bottom of the list.

Did you see this comment?

This means that if we fail to load an image the error will always be "Unsupported image format" and we lose any informative error set by the loader.

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

We could also move TIFF to the bottom of the list.

Did you see this comment?

This means that if we fail to load an image the error will always be "Unsupported image format" and we lose any informative error set by the loader.

Yep, just thinking if there is a nice way to handle that :)

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

Moving TIFF to the bottom would probably fix my issue; However, I'm a little bit worried that it may cause others.

What's your opinion on that? Moving TIFF to the bottom is the easiest way, but I could spend some more time & fix the SDL_GetError() issue in my PR.

@slouken
Copy link
Collaborator

slouken commented May 12, 2025

Fixing the GetError() issue is probably the best route.

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

GetError() issue is now fixed by tracking how many load attempts we've made.
Btw, I tried to follow the coding standard of the file, but if there is something you'd like to change, just let me know

@slouken
Copy link
Collaborator

slouken commented May 12, 2025

You actually need to save off the error in the case where an image load was attempted, as the error might be overridden by a subsequent is() call.

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

Did not account for that, sry
Fixed (?)

@slouken
Copy link
Collaborator

slouken commented May 12, 2025

Looks good. We need to do the same in IMG_LoadAnimationTyped_IO()

@sezero
Copy link
Contributor

sezero commented May 12, 2025

I'm not 100% comfortable with this patch

@Retro52
Copy link
Author

Retro52 commented May 12, 2025

I can see why, it may be too much to fix, possibly, one small edge case

We are going to keep the original version of it anyway, cause without it, I'd have to go and manually find all the broken images & convert them to other formats, like PNG.

On the other hand, I hate to modify original source code, and since Apple is (almost) definitely not going to do anything about it, I thought that maybe an official fix is possible

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