Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

towerofnix
Copy link
Member

@towerofnix towerofnix commented Jul 1, 2024

Related to leopard-js/leopard-mentors#4.

The main substantive change here is that Renderer.renderSprite will now always treat sprites with NaN or non-number size 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 the SpeechBubbleSkin.getTexture and VectorSkin.getTexture interfaces, which expect a non-NaN scale, and some light refactoring for VectorSkin._getMipmap and Renderer.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 into Expected a number, sprite TiledChevron size is NaN. Treating as 100%..

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.)
@PullJosh
Copy link
Collaborator

PullJosh commented Jul 3, 2024

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. :)

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.

None yet

2 participants