mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-07-03 10:20:46 -04:00
Fix costume sizes appearing as 0x0 in GUI
This commit is contained in:
parent
4afa7f5f8b
commit
423bb700c3
1 changed files with 9 additions and 4 deletions
|
@ -196,12 +196,17 @@ class SVGSkin extends Skin {
|
|||
const svgText = serializeSvgToString(svgTag, true /* shouldInjectFonts */);
|
||||
this._svgImageLoaded = false;
|
||||
|
||||
const {x, y, width, height} = svgTag.viewBox.baseVal;
|
||||
// While we're setting the size before the image is loaded, this doesn't cause the skin to appear with the wrong
|
||||
// size for a few frames while the new image is loading, because we don't emit the `WasAltered` event, telling
|
||||
// drawables using this skin to update, until the image is loaded.
|
||||
// We need to do this because the VM reads the skin's `size` directly after calling `setSVG`.
|
||||
// TODO: return a Promise so that the VM can read the skin's `size` after the image is loaded.
|
||||
this._size[0] = width;
|
||||
this._size[1] = height;
|
||||
|
||||
// If there is another load already in progress, replace the old onload to effectively cancel the old load
|
||||
this._svgImage.onload = () => {
|
||||
const {x, y, width, height} = svgTag.viewBox.baseVal;
|
||||
this._size[0] = width;
|
||||
this._size[1] = height;
|
||||
|
||||
if (width === 0 || height === 0) {
|
||||
super.setEmptyImageData();
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue