Repository navigation
fix(馃悰): register ImageBitmap so it can cross to worklet runtimes - #576
Merged
Merged
Conversation
RNWebGPUManager::installConstructors installed every WebGPU class except ImageBitmap, so its brand was never registered with NativeObjectRegistry. Sending an ImageBitmap to a worklet runtime then threw "No native class registered for brand: ImageBitmap" while unboxing it, inside the Worklets serializer, which aborts the app. Installing its constructor registers the brand, and also makes `instanceof ImageBitmap` work on the main runtime and on runtimes that call installWebGPU(). The worklet serialization spec round-trips a decoded ImageBitmap through a worklet runtime and checks its size, its class there and that the same object comes back.
Owner
|
that's a great catch thank you |
wcandillon
self-requested a review
October 18, 2026 17:43
|
馃帀 This PR is included in version 0.17.0 馃帀 The release is available on:
Your semantic-release bot 馃摝馃殌 |
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.
Sending an
ImageBitmapto a worklet runtime aborts the app. In my case it was a bitmap decoded withcreateImageBitmapon the JS thread and handed to a scene running on acreateWorkletRuntimeworker. Other WebGPU objects (buffers, textures, the device) cross fine.The exception thrown there is
No native class registered for brand: ImageBitmap.What
Unboxing a WebGPU object on another runtime looks up its class brand in
NativeObjectRegistry. A brand is only registered by that class'sinstallConstructor.RNWebGPUManager::installConstructorscalls it for every WebGPU class exceptImageBitmap, so its brand is never registered, and the throw inside the Worklets serializer terminates the app.Fix
Add
ImageBitmap::installConstructor(runtime)toinstallConstructors, next to the other classes. As a side effect,ImageBitmapnow exists as a global on the main runtime and on runtimes that callinstallWebGPU().x instanceof ImageBitmapthen works there as it does on the web; before, it threw aReferenceError(three.js checkstexture.image instanceof ImageBitmapwithout atypeofguard inTextureNode).Test
WorkletSerialization.spec.tsgains a case that decodes a PNG withcreateImageBitmap, sends the bitmap to a worklet runtime and back, and checks its size there,instanceof ImageBitmapon that runtime, and that the same object comes back. I ran it on an iPhone. It passes with the fix, and without it the app aborts with the crash above. I haven't run it on Android.Canvashas the same gap: it's the only other native object class missing frominstallConstructors.