Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPU backend: "Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer" if buffer is destroyed #6202

Open
kpreid opened this issue Sep 3, 2024 · 0 comments
Labels
area: api Issues related to API surface backend: webgpu Issues with direct interface with WebGPU type: bug Something isn't working

Comments

@kpreid
Copy link
Contributor

kpreid commented Sep 3, 2024

Description

Map a buffer for reading (update after #7007: must map for writing and actually write, instead), then destroy() it before dropping its BufferView, and get this error:

wasm-bindgen: imported JS function that was not marked as `catch` threw an error:
Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer

Stack:
TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
    at Uint8Array.set (<anonymous>)
    at http://127.0.0.1:49227/wasm-bindgen-test:2772:25
    at logError (http://127.0.0.1:49227/wasm-bindgen-test:242:18)
    at imports.wbg.__wbg_set_a47bac70306a19a7 (http://127.0.0.1:49227/wasm-bindgen-test:2771:66)
    at browser-f9157397fa96c579.wasm.js_sys::Uint8Array::set::h93600a3ef01210e9 (http://127.0.0.1:49227/wasm-bindgen-test_bg.wasm:wasm-function[16282]:0x878474)
    at browser-f9157397fa96c579.wasm.<wgpu::backend::webgpu::BufferMappedRange as core::ops::drop::Drop>::drop::h68cdd1b1ee07437b (http://127.0.0.1:49227/wasm-bindgen-test_bg.wasm:wasm-function[10012]:0x7fca51)
    at browser-f9157397fa96c579.wasm.core::ptr::drop_in_place<wgpu::backend::webgpu::BufferMappedRange>::hadbe2842852a0293 (http://127.0.0.1:49227/wasm-bindgen-test_bg.wasm:wasm-function[10624]:0x815f77)

There are two problems here:

  1. This should either succeed or be a wgpu validation error.
  2. Why is it even trying to write back, when the mapping was for reading? That's not a bug, but it's certainly an inefficiency. Fixed by Don’t copy buffer data back to JS if unnecessary, in WebGPU backend. #7007

Platform

wgpu version: 22.1.0
Browser version: Chrome 128.0.6613.113 (macOS)

@cwfitzgerald cwfitzgerald added type: bug Something isn't working area: api Issues related to API surface backend: webgpu Issues with direct interface with WebGPU labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: api Issues related to API surface backend: webgpu Issues with direct interface with WebGPU type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants