Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.6k
Fix: call failureCallback if omggif fails to parse GIF in loadImage#8047
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
🎉 Thanks for opening this pull request! For guidance on contributing, check out ourcontributor guidelines and otherresources for contributors! Thank You! |
ThomasFinnern commentedAug 24, 2025
is calling "failureCallback(e); on failing gif ... safe ? Or does it enable a possible call of a not wanted function. |
@ThomasFinnern Thanks for raising this! failureCallback here is user-supplied (similar to the success callback), so calling it with the error object is consistent with how other loading functions behave in p5.js. It shouldn’t allow unwanted function calls since the user has to explicitly pass the callback. Still, I appreciate the point — good to double-check! |
}else{ | ||
console.error(e); | ||
} | ||
finishCallback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think for consistency sake with other loading functions we don't callfinishCallback()
here which will resolve thepreload
even in the case of an error.
Resolves#8021
Changes:
Wrapped the omggif.GifReader constructor in a try/catch block in loading_displaying.js.

If a GIF cannot be parsed, the failureCallback of loadImage is now called with the error, instead of throwing an uncatchable exception.
This allows sketches to handle image loading errors gracefully and prevents the sketch from crashing.
Tested locally with a broken GIF using a simple HTML test file (test-gif-error.html).
Screenshots of the change:
When loading a broken GIF, the failure callback is called and the sketch continues running (see console and page output in the test file).
PR Checklist
npm run lint passes
Inline reference is included / updated (not applicable)
Unit tests are included / updated (manual test provided)
test-gif-error.html ( p5.js --> create [ test-gif-error.html ] )
code in [[ test-gif-error.html ]]
<script src="lib/p5.js"></script> <script> function preload() { loadImage( "broken.gif", // Use a GIF that omggif cannot parse (img) => console.log("Loaded!", img), (err) => { console.error("Properly handled error:", err); document.body.innerHTML += "Failure callback called!
"; } ); } function setup() { createCanvas(100, 100); background(200); } </script>