Repository navigation
fix(napi): texSubImage2D from a WebGPU canvas throws instead of panicking - #188
Conversation
…king The WebGPU-canvas arm of texSubImage2D was a todo!(), so the call panicked inside the Node-API callback, which can take down the host process. Return the same "not supported" error texImage2D already returns for a WebGPU canvas source.
|
No actionable comments were generated in the recent review. WalkthroughWhen ChangesWebGPU canvas source handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Bug fix Suggested reviewers: Merge Risk:
|
|
@coderabbitai review |
Action performed
|
A WebGPU canvas used as a WebGL texture source threw (texImage2D) or, before #188, panicked (texSubImage2D). Both now read the canvas's frame (the current texture if one is out, else the last presented frame) as unpremultiplied RGBA8 and upload it, like a 2D canvas source. canvas-c: toDataURL's copy-and-map step is now with_mapped_texture, shared with the new read_rgba8; canvas_native_webgl_tex_{,sub_}image2d_webgpu return false when there is no 8-bit frame, which the binding throws for. Specs: toDataURL pixel check for a WebGPU canvas (all platforms), and texImage2D/texSubImage2D from a WebGPU canvas (Windows for now).
Problem
texSubImage2Don a WebGL or WebGL2 context panics when the pixel source is a WebGPU canvas. That arm of the source match incrates/canvas-napi/src/gl/base.rswas stilltodo!("Implement drawImage for GPUContext"). A panic inside a Node-API callback isn't a JS exception the caller can catch, and it can bring down the host process (NativeScript Windows, Node).texImage2Dalready handles the same case without panicking: it returnsError::from_reason("texImage2D from a WebGPU canvas is not supported").Fix
The
Either4::D(_)(WebGPU) arm oftexSubImage2Dnow returns the matching error:tex_sub_image_2_dalready returnsResult<()>, so the caller gets a thrown JSErrorinstead of a crash. Nothing else changes. This was the onlytodo!()/unimplemented!()in the Node-API crates.Related to #131 (Node-API support). It doesn't close it.
Validation
Result<()>, and it uses the sameError::from_reasonform as thetexImage2Darm about 200 lines above.cargo check -p canvas-napion macOS stopped while buildingskia-bindingsfrom source, becauseninjawasn't installed. That failure is unrelated to this change. I'm relying on CI for the build.crates/canvas-napi/__test__source tests skip on anything other than Windows (process.platform !== 'win32'), and I don't have a Windows host. A test incanvas-sources.test.mjsthat expectstexSubImage2D(…, webgpuCanvas)to throw would cover this. I can add one if you'd like it in this PR.Summary by CodeRabbit
texSubImage2Dnow reports an error for unsupported WebGPU canvas sources instead of crashing.