Skip to content

Commit

Permalink
fix webgl crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Jan 10, 2024
1 parent ef5abe3 commit b666de7
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ impl Instance {
let handle_origin;

let target = target.into();
let unsafe_target = match target {
let mut surface = match target {
SurfaceTarget::Window(window) => {
let raw_display_handle = window
.display_handle()
Expand All @@ -1897,10 +1897,12 @@ impl Instance {

handle_origin = Some(window);

SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
}
unsafe {
self.create_surface_unsafe(SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
})
}?
}

#[cfg(any(webgpu, webgl))]
Expand All @@ -1912,10 +1914,14 @@ impl Instance {
let raw_window_handle = raw_window_handle::WebCanvasWindowHandle::new(obj).into();
let raw_display_handle = raw_window_handle::WebDisplayHandle::new().into();

SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
}
// Note that we need to call this while we still have `value` around.
// This is safe without storing canvas to `handle_origin` since the surface will create a copy internally.
unsafe {
self.create_surface_unsafe(SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
})
}?
}

#[cfg(any(webgpu, webgl))]
Expand All @@ -1928,14 +1934,17 @@ impl Instance {
raw_window_handle::WebOffscreenCanvasWindowHandle::new(obj).into();
let raw_display_handle = raw_window_handle::WebDisplayHandle::new().into();

SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
}
// Note that we need to call this while we still have `value` around.
// This is safe without storing canvas to `handle_origin` since the surface will create a copy internally.
unsafe {
self.create_surface_unsafe(SurfaceTargetUnsafe::RawHandle {
raw_display_handle,
raw_window_handle,
})
}?
}
};

let mut surface = unsafe { self.create_surface_unsafe(unsafe_target) }?;
surface._surface = handle_origin;

Ok(surface)
Expand Down

0 comments on commit b666de7

Please sign in to comment.