Description
Many wgpu-core
functions return both an object ID and an error when they fail. For typical functions that construct a new object, the returned ID when there is an error refers to a new, invalid object, which is fine. But in the case of CommandEncoder.finish
, there is a problem, because wgpu-core
does not have distinct object types for command encoders and command buffers. The returned ID (for a command buffer) is just the ID of the encoder being finished. This means that calling CommandEncoder.finish
multiple times creates multiple command buffer objects with the same ID, which can cause problems if those objects are not dropped correctly.
According to the spec, calling finish()
multiple times for the same encoder should result in a validation error. With the wgpu
API, finish()
consumes the encoder so it is not possible to call multiple times. In deno, as of #7808, calling finish()
multiple times raises a TypeError
immediately in order to avoid returning a duplicate command buffer. For Firefox, see the first comment.