-
Notifications
You must be signed in to change notification settings - Fork 29
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
Defend renderer against NaN or non-number sprite size #199
Conversation
Note that this prints the actual name of the sprite (or rather its constructor name), which should aid in identifying which sprites are broken, and tell that something's gone wrong with setting its size.
(WeakSet has similar browser support as WeakMap.)
I will be gone for a few days for the 4th of July so if @adroitwhiz is happy with this (or any other PR) feel free to merge. Otherwise I'll look into it when I return. :) |
Still on vacation but I have some time at a coffee shop. I created a test project to try this out, and I'm still experiencing some issues. When I set the sprite size to NaN ( Additionally, setting the sprite size to |
Thanks for checking that!! Okay, so it turns out the issue with NaN is that we actually perform the So we moved the math for getting a sprite size into This makes NaN actually render as 100%. Thanks for the demo project catching it! |
I don't think we can super reasonably handle setting the sprite size to massive values in this PR, because that's part of the "cap to maximum and minimum sizes" logic that would belong as its own thing — but And, I think it's reasonable to, within the same function, banish any negative number. Negative size is completely meaningless in Scratch. In Leopard it doesn't appear to "break" - the sprite just goes invisible - but it's not rendering the speech bubble either, which is weird. Here's our thought:
Edit: ^ These updated checks are implemented in the commits below! |
We've followed up with an issue for handling minimum/maximum size: #202 |
There's no need to harden these interfaces against NaN if we are not also going to harden them against e.g. negative numbers or the infinities, which warrants a more thorough investigation. We keep the tidied logic for _createMipmap because it still helps make that function and getTexture (both wtihin VectorSkin) more focused, without actually changing any behavioral meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and behavior looks great 👍
It seems like @adroitwhiz has code review covered, so I'm happy to merge once everyone else is happy.
Related to leopard-js/leopard-mentors#4. Resolves #105.
The main substantive change here is that
Renderer.renderSprite
will now always treat sprites with NaN or non-numbersize
as being 100%. This isn't "right" per se - "set size to NaN" is equal to "set size to 0" - but sprites should never be size NaN anyway, and I figure "treating as 100%" is more clearly-broken behavior than "treating as literally invisible". (Matching Scratch exactly would mean setting the size to the minimum valid size for that sprite's current costume, which the renderer isn't suited to handle on its own.)Secondary changes include
warnings in thesome light refactoring forSpeechBubbleSkin.getTexture
andVectorSkin.getTexture
interfaces, which expect a non-NaN scale, andVectorSkin._getMipmap
andRenderer.renderSprite
.This doesn't fix the case project (leopard-js/leopard-mentors#4), but it does clarify the error from a generic
WebGL: INVALID_VALUE: texImage2D: no canvas
intoExpected a number, sprite TiledChevron size is NaN. Treating as 100%.
.