Skip to content

Commit

Permalink
metal: check if in the main thread when calling create_surface
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jun 6, 2022
1 parent a3b2418 commit f5cb4d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use objc::{
declare::ClassDecl,
msg_send,
rc::autoreleasepool,
runtime::{Class, Object, Sel, BOOL, YES},
runtime::{Class, Object, Sel, BOOL, NO, YES},
sel, sel_impl,
};
use parking_lot::Mutex;
Expand Down Expand Up @@ -84,6 +84,11 @@ impl super::Surface {
panic!("window does not have a valid contentView");
}

let is_main_thread: BOOL = msg_send![class!(NSThread), isMainThread];
if is_main_thread == NO {
panic!("create_surface cannot be called in non-ui thread.");
}

let main_layer: *mut Object = msg_send![view, layer];
let class = class!(CAMetalLayer);
let is_valid_layer: BOOL = msg_send![main_layer, isKindOfClass: class];
Expand Down

0 comments on commit f5cb4d8

Please sign in to comment.