mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
metal: check if in the main thread when calling create_surface (#2736)
This commit is contained in:
@@ -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;
|
||||
@@ -74,6 +74,7 @@ impl super::Surface {
|
||||
}
|
||||
}
|
||||
|
||||
/// If not called on the main thread, this will panic.
|
||||
#[allow(clippy::transmute_ptr_to_ref)]
|
||||
pub unsafe fn from_view(
|
||||
view: *mut c_void,
|
||||
@@ -84,6 +85,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];
|
||||
|
||||
@@ -1708,6 +1708,7 @@ impl Instance {
|
||||
///
|
||||
/// - Raw Window Handle must be a valid object to create a surface upon and
|
||||
/// must remain valid for the lifetime of the returned surface.
|
||||
/// - If not called on the main thread, metal backend will panic.
|
||||
pub unsafe fn create_surface<W: raw_window_handle::HasRawWindowHandle>(
|
||||
&self,
|
||||
window: &W,
|
||||
|
||||
Reference in New Issue
Block a user