fix(core): read texture dimensions from the plain object image form - #10539
Open
mhayk wants to merge 1 commit into
Open
fix(core): read texture dimensions from the plain object image form#10539mhayk wants to merge 1 commit into
mhayk wants to merge 1 commit into
Conversation
`createTexture` reads `width`/`height` off `image.data`. Browser image
objects (ImageData, ImageBitmap, canvas, ...) are wrapped as
`{data: browserImage}` first, so their dimensions are found there. The
documented plain object form `{data: <Uint8Array>, width, height}` carries
them on the object itself, so both were `undefined` and
`device.getMipLevelCount()` returned `NaN`.
Combined with the default `mipmapFilter: 'linear'` sampler, the resulting
texture was incomplete and sampled as opaque black, painting black over
everything beneath the layer's bounds. Read the dimensions from whichever
level carries them.
Verified by pixel readback: a BitmapLayer using the plain object form
sampled `[0, 0, 0, 255]` before and `[255, 255, 0, 255]` after, matching the
equivalent `ImageData`.
Fixes visgl#10371
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Fixes #10371 — the documented plain object
imageform renders as opaque black, painting black over everything beneath the layer's bounds.BitmapLayer's docs list{data: <Uint8Array>, width, height}as a supportedimagevalue (bitmap-layer.md), but in 9.x it does not render.Root cause
createTexture()inmodules/core/src/utils/texture.tsreads the dimensions offimage.data:Browser image objects (
ImageData,ImageBitmap, canvas, …) hit the branch above that wraps them asimage = {data: browserImage}, soimage.data.width/heightexist and everything works. The plain object form hasconstructor.name === 'Object', so it is not wrapped — it stays{data, width, height}, wheredatais the raw typed array. Both dimensions come backundefined, so:The texture is created with
mipLevels: NaN. Combined with the defaultmipmapFilter: 'linear'inDEFAULT_TEXTURE_PARAMETERS, the texture is incomplete and samples as(0, 0, 0, 1).This runs through the shared
imageprop type inmodules/core/src/lifecycle/prop-types.ts, so it affects everyimage-typed prop (BitmapLayer.image,IconLayer.iconAtlas,TextLayer, …), not justBitmapLayer.Changes
modules/core/src/utils/texture.ts— read the dimensions from whichever level actually carries them:One-line behavioral change; the browser-object path is untouched.
Validation
New
test/modules/core/utils/texture.spec.tscovering both forms, assertingwidth,height, and a validmipLevels. Confirmed it actually catches the bug — with the fix reverted:Also verified end-to-end by pixel readback, rendering a solid-yellow bitmap through both forms and sampling the canvas centre:
ImageData[0, 0, 0, 255]— black[255, 255, 0, 255][255, 255, 0, 255][255, 255, 0, 255]This matches the reporter's measurements. That probe was a throwaway and is not included — the committed test asserts the root cause (
mipLevels) instead, since the repo keeps visual checks intest/renderwith golden images.Suites run:
core+layersheadless — 84 files, 360 tests, all passing.biome checkclean on all three files.Not run locally:
yarn test-render. The render project needs headed chromium, and the Playwright build this checkout pins (1217) currently 400s on every CDN mirror, so I could not install it. No existing golden image exercises the plain-object path — allbitmap-layerrender cases load images by URL — so none should shift, but that is worth confirming in CI.Also note the full headless suite is flaky on my machine independently of this change: repeated runs on unmodified
masterfail a varying 2–3 tests (LoadingWidgetconsistently, plus rotatingWebGLAggregator/MapboxOverlay/react-mount failures). None are incoreorlayers.