Set zero-sized SVG MIPs to empty texture #539
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
IndexSizeError
s from messing up SVG skin rendering.Note that
IndexSizeError
s 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 ofscratch-render
.