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

fix panic with as_hal functions #2871

Merged
merged 1 commit into from
Jul 12, 2022

Conversation

i509VCB
Copy link
Contributor

@i509VCB i509VCB commented Jul 11, 2022

Checklist

  • Run cargo clippy.
  • Run RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections
Fixes #2862

Description
The as_hal family of functions will invoke the callback with None if the wrong api is used as the generic type. This is because the HalApi generic performs lookup in a different hub. However the get function in the storage will fail if the id used for lookup is not in the storage (because you specified the wrong generic type) and therefore panic.

To solve this, a try_get function is used for all as_hal functions to ensure that as_hal will actually return None instead of panicking.

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.

LGTM, will need to make sure this behavior sticks with the new hubs

@cwfitzgerald cwfitzgerald merged commit db24c06 into gfx-rs:master Jul 12, 2022
cwfitzgerald pushed a commit to cwfitzgerald/wgpu that referenced this pull request Jul 14, 2022
cwfitzgerald pushed a commit that referenced this pull request Jul 14, 2022
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.

Adapter[0] does not exist panic when calling Adapter::as_hal
2 participants