Skip to content

Set zero-sized SVG MIPs to empty texture #539

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

Merged
merged 1 commit into from
Jan 9, 2020

Conversation

adroitwhiz
Copy link
Contributor

@adroitwhiz adroitwhiz commented Jan 9, 2020

Depends on scratchfoundation/scratch-svg-renderer#116

Resolves

Resolves #538

Proposed Changes

This PR adds a check in SVGSkin.createMIP that checks if one of the SVG renderer's canvas dimensions is 0. If so, it returns an empty image texture.

It also removes the check from getTexture that checks whether the SVG renderer's canvas width or height are 0, as it is now unnecessary and may cause an error: it checks the current canvas width or height, not the width and height of the proper mipmap's canvas.
This means if you e.g. render a mipmap at scale 1, then render it at a very small scale that makes one of its texture dimensions 0, it won't appear again even at mipmap scale 1, because it was last rendered at that small scale and so the SVG renderer's canvas width/height will remain 0.

Reason for Changes

Along with scratchfoundation/scratch-svg-renderer#116, this prevents IndexSizeErrors from messing up SVG skin rendering.

Note that IndexSizeErrors have, for a long time now, been thrown when zero-sized skins have been rendered, but they only became a problem with #527 because thrown errors can't propagate through callbacks, which the previous SVG drawing API used extensively.

EDIT: actually, it looks like it was the original SVGMIP patch that introduced the issue (although #527 didn't fix it; if you go into fullscreen with a 0x0 sprite, it still breaks). scratch-gui wasn't getting the updated version of scratch-render.

Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay, thanks for figuring that out!

@fsih fsih merged commit ed889bc into scratchfoundation:develop Jan 9, 2020
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.

Costume stops updating stage after being cleared (not yet on prod)
2 participants