fix(webgpu): reading a mapped buffer throws on a detached ArrayBuffer - #4
Merged
Merged
Conversation
Cloning a buffer duplicated its cached mapped ArrayBuffer rather than sharing it, so unmapping through one clone left every other clone holding an ArrayBuffer that Javascript had already detached. The next read built a Uint8Array view over that buffer and threw "Cannot perform Construct on a detached ArrayBuffer". The same applies to the mapped range recorded by map_async, which was invisible to any other clone. Upstream carries this same change from 29.0.1 onward; 27.0.4 is still affected.
IceSentry
approved these changes
Aug 5, 2026
|
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: IceSentry The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
Connections
None. Found while debugging the SpatialEngine WASM viewer after fsl_libs moved from wgpu 26 to 27.
Description
Reading a mapped buffer on the WebGPU backend can throw "Cannot perform Construct on a detached ArrayBuffer".
WebBuffer caches the array buffer from getMappedRange so several Rust-side reads share one JS call. Since 27, DispatchBuffer holds WebBuffer by value rather than behind an Arc, so cloning a buffer copies that cache instead of sharing it. Unmapping through one clone clears only its own copy while Javascript detaches the array buffer for every clone, and the next read builds a view over the detached buffer. The range recorded by map_async diverges the same way.
An Rc restores shared ownership, matching upstream from 29.0.1 onward. The patch-27.0.4 branch is still affected and wants the same change.
Testing
Reproduced in the SpatialEngine WASM viewer, where volumesight's streaming readback clones a buffer into its recycle pool before unmapping it. The error appears on every page load with 27.0.1, and bisecting showed it absent on 26.0.1. Check, clippy and fmt for wgpu on wasm32-unknown-unknown all pass.
Not run against wgpu's own test suite and not exercised on a native backend, though only the WebGPU path changes. A reviewer with a WebGPU mapping test should confirm nothing relies on clones having independent caches.
Squash or Rebase?
Single commit, ready to rebase.