Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Satish-Medar wants to merge1 commit intoprocessing:main
base:main
Choose a base branch
Loading
fromSatish-Medar:fix-gif-failure-callback

Conversation

Satish-Medar
Copy link

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:
Screenshot 2025-08-24 111218

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>

@welcomeWelcome
Copy link

welcomebot commentedAug 24, 2025

🎉 Thanks for opening this pull request! For guidance on contributing, check out ourcontributor guidelines and otherresources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure toadd yourself to thelist of contributors on the readme page !

Thank You!

@ThomasFinnern
Copy link

is calling "failureCallback(e); on failing gif ... safe ? Or does it enable a possible call of a not wanted function.
Just an offside comment with good intention. I am sorry if it is on the wrong place here.

@Satish-Medar
Copy link
Author

@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();
Copy link
Member

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@limzykennethlimzykennethlimzykenneth left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

loadImage with GIFs that can't be parsed throws an error that breaks the sketch
4 participants
@Satish-Medar@ThomasFinnern@limzykenneth@Satish11222

[8]ページ先頭

©2009-2025 Movatter.jp