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

Make DeviceLostClosure.from_c mutate the closure before dropping it. #5032

Merged
merged 2 commits into from
Jan 14, 2024

Conversation

bradwerth
Copy link
Contributor

@bradwerth bradwerth commented Jan 10, 2024

Description
Since DeviceLostClosureC requires that it be called before it is dropped, and we receive an existing DeviceLostClosureC struct as param in DeviceLostClosure.from_c, we need to mark the param as called before it drops out of scope.

Testing
Tested by embedders using DeviceLostClosure.from_c.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@bradwerth bradwerth requested a review from a team as a code owner January 10, 2024 20:09
wgpu-core/src/device/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@nical nical left a comment

Choose a reason for hiding this comment

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

nit: renaming called into consumed would make this easier to understand.

wgpu-core/src/device/mod.rs Outdated Show resolved Hide resolved
This clarifies that the Rust and C-style callbacks/closures need to be
consumed (not called) before they are dropped. It also makes the from_c
function consume the param closure so that it can be dropped without
panicking.

It also relaxes the restriction that the callback/closure can only be
called once.
@nical nical enabled auto-merge (squash) January 12, 2024 23:26
@nical nical merged commit f89bd3b into gfx-rs:trunk Jan 14, 2024
27 checks passed
@bradwerth bradwerth deleted the callBeforeDropCallbackC branch January 16, 2024 22:09
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