Skip to content

Conversation

@jerzywilczek
Copy link
Contributor

Connections
None

Description
Currently, some structures in vulkan and gles have DropGuards. Those are intended to allow creation of wgpu_hal structs, such as Device, from their raw counterparts initialized manually by the user. The drop guard signals to the user when the resource is not used by wgpu anymore so that they know it can be cleaned up.

The problem is that DropGuards are not last members of wgpu_hal structs. Struct's fields are dropped in declaration order. This can lead to problems, such as the fields defined later in the struct requiring the underlying raw structure to be alive in order to free themselves properly, and the raw structure not being alive because the DropGuard was dropped earlier.

This patch moves the drop guards to the end of their parent structs.

Testing
Not sure how to test this or if testing is necessary

Squash or Rebase?
Squash I guess...

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
    181 failed tests, with and without the changes
  • If this contains user-facing changes, add a CHANGELOG.md entry.

This makes them be dropped after all other fields, which may be
necessary, since the drop guard keeps the underlying resources alive.
@cwfitzgerald cwfitzgerald self-assigned this Oct 15, 2025
@jerzywilczek jerzywilczek requested a review from kpreid October 16, 2025 10:09
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big oops!

@cwfitzgerald cwfitzgerald merged commit a70b833 into gfx-rs:trunk Oct 16, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants