scratchfoundation / scratch-gui

Graphical User Interface for creating and running Scratch 3.0 projects.
https://scratchfoundation.github.io/scratch-gui/develop/
BSD 3-Clause "New" or "Revised" License
4.47k stars 3.59k forks source link

Uploaded costumes disappear #4711

Open ChampikaF opened 5 years ago

ChampikaF commented 5 years ago

Expected Behavior

Costumes should not disappear

Actual Behavior

Uploaded svg costumes disappear on project load and then only reappear when going into the paint editor and moving the costume around on the canvas. This happens repeatedly to certain costumes in the project referenced below.

Might be related to #2007 but these costumes haven't been switched between vector and bitmap. These costumes were created in photoshop and saved as svg.

Steps to Reproduce

Operating System and Browser

Can replicate on Debian, Chrome.

thisandagain commented 5 years ago

This is an issue we have been seeing on Safari in particular (both on MacOS and iOS). Needs further investigation.

thisandagain commented 5 years ago

/cc @kchadha @BryceLTaylor

BryceLTaylor commented 5 years ago

There are a few related issues to sprites not appearing on the stage. Many of them have to do with svg files imported from other software: https://github.com/LLK/scratch-paint/issues/816 https://github.com/LLK/scratch-paint/issues/782 https://github.com/LLK/scratch-paint/issues/793

spectranaut commented 5 years ago

@BryceLTaylor do you know a way to fix/resave the SVGs so that they aren't broken in Scratch?

thisandagain commented 5 years ago

@ktbee Do you mind looking into this after you wrap up your current task?

/cc @kchadha

ktbee commented 5 years ago

@thisandagain sure thing!

ktbee commented 5 years ago

After digging into this a little bit, I'm finding that this issue at least originates outside of Scratch. In Chrome and Safari this Codepen's canvas silently fails to load the cloud SVG, but in Firefox it loads successfully: https://codepen.io/ktbee/pen/zXZbOQ

I'm taking a look at why Chrome/Safari are able to display this SVG after updating it in the costume editor, perhaps we can make sure this update logic can happen on first render as well. Also let me know if anyone has thoughts or has run into something similar before.

gnarf commented 5 years ago

I was messing around a bit with this pen trying various things... found some interesting followups:

<img src=""> doesn't render either:

Chrome Left - FF right image

but if you load the URL into the address bar chrome seems to be able to display it:

image

gnarf commented 5 years ago

Found it... Viewing the source of the cloud SVG:

<image x="57.5376" y="359.28938" transform="scale(0.46927,0.46927)" width="358" height="202" 
xlink:href="data:img/png;base64,........">

img/png is not a mime type and needs to say image/png and then the image loads correctly

ktbee commented 5 years ago

Thanks for tracking that down @gnarf! I'll add a fix in svg-renderer to account for non-existent mime types.

thisandagain commented 5 years ago

Wonderful! Thanks @gnarf and @ktbee!

ktbee commented 5 years ago

For anyone curious, I also submitted an issue with the Chromium team for this browser incompatibility: https://bugs.chromium.org/p/chromium/issues/detail?id=952423

BryceLTaylor commented 5 years ago

Inkscape also appears to produce .svg images with a similar problem: https://github.com/LLK/scratch-gui/issues/4242

ktbee commented 5 years ago

For the original issue of SVGs with invalid mime types, this has been solved by https://github.com/LLK/scratch-svg-renderer/pull/82. Existing projects with this issue may just need to toggle the costume type between vector, bitmap and back to vector again for this fix to take effect. It will be fine for new costumes as they're uploaded as well.

ktbee commented 5 years ago

Re-opening this for now since the fix in https://github.com/LLK/scratch-svg-renderer/pull/82 allows the SVG to appear on the stage but not in the paint editor. I'm working on a fix now for the paint editor.

ktbee commented 5 years ago

After digging into why this fix wasn't working, I found part of the issue was that my test file had a new line inserted on the first line of the SVG, which was causing it to fail to load for unrelated reasons. However, the sprite tile still doesn't show the cloud, so I'll leave this open for now until that is fixed.

Screen Shot 2019-05-23 at 1 34 05 PM