gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 551 forks source link

Prevent accessing NSView from other threads #3753

Closed zakorgy closed 3 years ago

zakorgy commented 3 years ago

Fixes #3704 PR checklist:

Tested it with the following patch:

diff --git a/examples/quad/main.rs b/examples/quad/main.rs
index 8989a75ef..676e5a198 100644
--- a/examples/quad/main.rs
+++ b/examples/quad/main.rs
@@ -114,13 +114,18 @@ fn main() {
         .append_child(&winit::platform::web::WindowExtWebSys::canvas(&window))
         .unwrap();

-    let instance = back::Instance::create("gfx-rs quad", 1).expect("Failed to create an instance!");

-    let surface = unsafe {
-        instance
-            .create_surface(&window)
-            .expect("Failed to create a surface!")
-    };
+    let other_thread = std::thread::spawn(move || {
+            let instance = back::Instance::create("gfx-rs quad", 1).expect("Failed to create an instance!");
+            let surface = unsafe {
+                instance
+                    .create_surface(&window)
+                    .expect("Failed to create a surface!")
+            };
+            (instance, surface)
+    });
+
+    let (instance, surface) = other_thread.join().unwrap();

     let adapter = {
         let mut adapters = instance.enumerate_adapters();
bors[bot] commented 3 years ago

Build succeeded: