mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Fix panic when creating a surface while no backend is available (#5166)
* Fix panic when creating a surface while no backend is available * changelog entry
This commit is contained in:
parent
0888a630a0
commit
45957088ad
@ -103,6 +103,7 @@ Bottom level categories:
|
|||||||
- Fix `serde` feature not compiling for `wgpu-types`. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149)
|
- Fix `serde` feature not compiling for `wgpu-types`. By @KirmesBude in [#5149](https://github.com/gfx-rs/wgpu/pull/5149)
|
||||||
- Fix the validation of vertex and index ranges. By @nical in [#5144](https://github.com/gfx-rs/wgpu/pull/5144) and [#5156](https://github.com/gfx-rs/wgpu/pull/5156)
|
- Fix the validation of vertex and index ranges. By @nical in [#5144](https://github.com/gfx-rs/wgpu/pull/5144) and [#5156](https://github.com/gfx-rs/wgpu/pull/5156)
|
||||||
- Device lost callbacks are invoked when replaced and when global is dropped. By @bradwerth in [#5168](https://github.com/gfx-rs/wgpu/pull/5168)
|
- Device lost callbacks are invoked when replaced and when global is dropped. By @bradwerth in [#5168](https://github.com/gfx-rs/wgpu/pull/5168)
|
||||||
|
- Fix panic when creating a surface while no backend is available. By @wumpf [#5166](https://github.com/gfx-rs/wgpu/pull/5166)
|
||||||
|
|
||||||
#### WGL
|
#### WGL
|
||||||
|
|
||||||
|
@ -471,6 +471,15 @@ pub enum RequestAdapterError {
|
|||||||
InvalidSurface(SurfaceId),
|
InvalidSurface(SurfaceId),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Error)]
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub enum CreateSurfaceError {
|
||||||
|
#[error("No backend is available")]
|
||||||
|
NoSupportedBackend,
|
||||||
|
#[error(transparent)]
|
||||||
|
InstanceError(#[from] hal::InstanceError),
|
||||||
|
}
|
||||||
|
|
||||||
impl Global {
|
impl Global {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
@ -483,7 +492,7 @@ impl Global {
|
|||||||
display_handle: raw_window_handle::RawDisplayHandle,
|
display_handle: raw_window_handle::RawDisplayHandle,
|
||||||
window_handle: raw_window_handle::RawWindowHandle,
|
window_handle: raw_window_handle::RawWindowHandle,
|
||||||
id_in: Option<SurfaceId>,
|
id_in: Option<SurfaceId>,
|
||||||
) -> Result<SurfaceId, hal::InstanceError> {
|
) -> Result<SurfaceId, CreateSurfaceError> {
|
||||||
profiling::scope!("Instance::create_surface");
|
profiling::scope!("Instance::create_surface");
|
||||||
|
|
||||||
fn init<A: HalApi>(
|
fn init<A: HalApi>(
|
||||||
@ -521,8 +530,7 @@ impl Global {
|
|||||||
hal_surface = init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle);
|
hal_surface = init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is only None if there's no instance at all.
|
let hal_surface = hal_surface.ok_or(CreateSurfaceError::NoSupportedBackend)??;
|
||||||
let hal_surface = hal_surface.unwrap()?;
|
|
||||||
|
|
||||||
let surface = Surface {
|
let surface = Surface {
|
||||||
presentation: Mutex::new(None),
|
presentation: Mutex::new(None),
|
||||||
|
@ -2812,7 +2812,7 @@ pub struct CreateSurfaceError {
|
|||||||
enum CreateSurfaceErrorKind {
|
enum CreateSurfaceErrorKind {
|
||||||
/// Error from [`wgpu_hal`].
|
/// Error from [`wgpu_hal`].
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
Hal(hal::InstanceError),
|
Hal(wgc::instance::CreateSurfaceError),
|
||||||
|
|
||||||
/// Error from WebGPU surface creation.
|
/// Error from WebGPU surface creation.
|
||||||
#[allow(dead_code)] // may be unused depending on target and features
|
#[allow(dead_code)] // may be unused depending on target and features
|
||||||
@ -2847,8 +2847,8 @@ impl error::Error for CreateSurfaceError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
impl From<hal::InstanceError> for CreateSurfaceError {
|
impl From<wgc::instance::CreateSurfaceError> for CreateSurfaceError {
|
||||||
fn from(e: hal::InstanceError) -> Self {
|
fn from(e: wgc::instance::CreateSurfaceError) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: CreateSurfaceErrorKind::Hal(e),
|
inner: CreateSurfaceErrorKind::Hal(e),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user