gfx-rs / gfx

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

macos metal backend crash with CA_ASSERT_MAIN_THREAD_TRANSACTIONS #3694

Open bnb-ashershen opened 3 years ago

bnb-ashershen commented 3 years ago

Hi!

My app doing render stuff in separate thread (not main), and when I try to run it with env var CA_ASSERT_MAIN_THREAD_TRANSACTIONS=1 (Xcode Instruments run it like this), I see crash in this line. If comment out described line application works fine, looks like only setAllowsNextDrawableTimeout message make CA transaction under the hood.

Error happens during creating swapchain through wgpu library.

macOS Big Sur 11.2.3 Crash error: _CoreAnimation: CA_ASSERT_MAIN_THREADTRANSACTIONS is set and an implicit transaction wasn't created on a main thread.

Thanks.

kvark commented 3 years ago

Wow, that's quite something... I don't know right off the bat how we should be handling this. gfx doesn't control threading, and we can't launch a helper thread just to do this (would be super awkward).

I wonder if just checking for the thread ID there would be an acceptable workaround? I.e. remember which thread owns the surface, and compare the current thread before calling setAllowsNextDrawableTimeout. If you want to try this and make a PR, that would be wonderful!