Skip to content

fix(BitmapSkin): Prevent WebGL errors for 0-dimension bitmaps#2552

Closed
aryanjsingh wants to merge 1 commit intoscratchfoundation:developfrom
aryanjsingh:fix/issue-417-painting-sprite-will-raise-webgl-invalid
Closed

fix(BitmapSkin): Prevent WebGL errors for 0-dimension bitmaps#2552
aryanjsingh wants to merge 1 commit intoscratchfoundation:developfrom
aryanjsingh:fix/issue-417-painting-sprite-will-raise-webgl-invalid

Conversation

@aryanjsingh
Copy link
Copy Markdown

Summary

Fixes a WebGL error that occurred when creating a new bitmap costume via the 'paint' button. The error was caused by attempting to create a texture from a source with zero width or height.

The fix is to use the _getBitmapSize static method to correctly check the dimensions of the incoming bitmap data at the beginning of setBitmap. This ensures that 0-width or 0-height bitmaps are handled gracefully before they can cause a WebGL error.

Changes

  • src/BitmapSkin.js: In setBitmap, the initial check for bitmap dimensions was not robust for all bitmap data types. This change replaces the simple property check with a call to _getBitmapSize, which correctly determines the bitmap's dimensions (e.g., using naturalWidth for images). This prevents 0x0 bitmaps from being passed to WebGL, fixing the reported errors.

Related Issue

Closes #417

@aryanjsingh aryanjsingh closed this Apr 4, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Apr 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Painting sprite will raise 'WebGL: INVALID_VALUE: texImage2D: no canvas'

1 participant