-
Notifications
You must be signed in to change notification settings - Fork 180
Panic when no adapters are available #117
Description
Similar to #105
Originally reported in parasyte/pixels#36
We try to catch any errors from wgpu::Adapter::request
to provide a "helpful" error message, but our error handler never gets called: https://github.com/parasyte/pixels/blob/98983d201db0639f51c264ade5cf876f8df65d1e/src/lib.rs#L412-L413
The backtrace points to the panic occurring here in wgpu-native
: https://github.com/gfx-rs/wgpu/blob/951641dcc50b355eda894c9a5cd6da057d48765b/wgpu-native/src/instance.rs#L473-L475
The wgpu::Adapter::request
method itself is suspicious. The docs claim it returns None
when an adapter cannot be found, but it is clearly hardcoded to return Some<T>
:
Lines 538 to 547 in cbdd74f
/// Retrieves an [`Adapter`] which matches the given options. | |
/// | |
/// Some options are "soft", so treated as non-mandatory. Others are "hard". | |
/// | |
/// If no adapters are found that suffice all the "hard" options, `None` is returned. | |
pub fn request(options: &wgn::RequestAdapterOptions) -> Option<Self> { | |
Some(Adapter { | |
id: wgn::wgpu_request_adapter(Some(options)), | |
}) | |
} |
Given these two issues, we're unable to capture the error (transform the None
into Result<_, E>
) because this method never returns None
. I would work on this, but unfortunately I don't know the best way to approach the extern "C"
interface. Should it just return Option<AdapterId>
?
Activity
fogti commentedon Nov 7, 2019
Actually, the unwrap lies in rust code here:
https://github.com/gfx-rs/wgpu/blob/c33b1e81fddf480f24e543cd3689b8991029d893/wgpu-native/src/instance.rs#L473-L475
It would be a good idea to call
request_adapter
directly.grovesNL commentedon Nov 7, 2019
In general we should avoid skipping the C API for functional changes like this, since we also want to allow other languages using the C API to fail gracefully too.
We can't return
Option<AdapterId>
in the C API because we don't haveOption
available in C, but we need to be able to use the return value there.We haven't implemented full WebGPU error handling yet, so for now the C API could use the special
Id::ERROR
forNone
and check for this in wgpu-rs. This is similar to the following check which we already have for swapchain errors:wgpu-rs/src/lib.rs
Line 1358 in cbdd74f
request_adapter
gfx-rs/wgpu#375parasyte commentedon Nov 7, 2019
Duplicate of gfx-rs/wgpu#368
Merge #375