Skip to content

Commit

Permalink
fix: crash on macOS
Browse files Browse the repository at this point in the history
The crash log:
'called `Option::unwrap()` on a `None` value'. (File: src/renderer/renderer.rs; Line: 109, Column: 18)

It is mainly because call DX12 on all platform.
After change to conditional choose GPU, macOS require get METAL in UI
thread

KNOWN ISSUE: the window is transparent in macOS, only the titlebar is
presented
  • Loading branch information
qinyuhang committed Apr 11, 2023
1 parent b630b64 commit 598b8e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/renderer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl WGpuRenderer {
let size = window.inner_size();

// The instance is a handle to our GPU
// Backends::all => Vulkan + Metal + DX12 + Browser WebGPU
let instance = Instance::new(Backends::DX12);
// Backends::all() => Vulkan + Metal + DX12 + Browser WebGPU
let instance = Instance::new(Backends::all());

// # Safety
// The surface needs to live as long as the window that created it.
Expand Down
7 changes: 5 additions & 2 deletions src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ pub fn create_window() {

let (txtemp, rx) = mpsc::channel::<Event<UserEvent>>();
let mut tx = Some(txtemp);

// the Instance::new(Backends::all()); in macos requires running in main thread
// otherwise it will throw error of running in non-UI thread
let wgpu_renderer = WGpuRenderer::new(&window);

let mut render_thread_handle = Some(thread::spawn(move || {
let initial_size = window.inner_size();

Expand Down Expand Up @@ -448,8 +453,6 @@ pub fn create_window() {
renderer.grid_renderer.font_dimensions,
);

let wgpu_renderer = WGpuRenderer::new(&window);

let mut window_wrapper = WinitWindowWrapper {
wgpu_renderer,
window,
Expand Down

0 comments on commit 598b8e9

Please sign in to comment.