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 in Storage::get #2657

Merged
merged 6 commits into from
May 14, 2022
Merged

Conversation

SparkyPotato
Copy link
Contributor

Description
When an Id with Index out of bounds of self.map is given to Storage::contains, Storage::get, or Storage::get_mut, it panics due to directly indexing the Vec. This PR fixes that, and makes contains return false, and get* return Err(InvalidId) like they should.

This also indirectly fixes a panic when Device::as_hal is invoked with an API that is not being used at the time.

Testing
This was tested by creating a device with Backends::Vulkan, and trying to get a Dx12 backend (Device::as_hal::<Dx12, _, _>) from it. It correctly gives the closure a None, instead of panicking as it did earlier.

wgpu-core/src/hub.rs Show resolved Hide resolved
wgpu-core/src/hub.rs Outdated Show resolved Hide resolved
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

@cwfitzgerald cwfitzgerald enabled auto-merge (squash) May 14, 2022 09:15
@cwfitzgerald cwfitzgerald merged commit 75b881e into gfx-rs:master May 14, 2022
@SparkyPotato SparkyPotato deleted the storage-invalid-id branch May 14, 2022 09:30
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.

2 participants