google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.35k stars 1.84k forks source link

Acquire a mutex before releasing CAMetalDrawables on main thread. #7888

Closed ullerrm closed 1 month ago

ullerrm commented 1 month ago

PresentDrawable was moved to main thread by default in google#7535 and stopped most crashes when a drawable is released. But there still appears to be crashes if a drawable is released on main thread at the same time that -nextDrawable is called from the Filament render thread. (It's likely that the drawable pool in CAMetalLayer is completely non-thread-safe.)

So, add a mutex to the swapchain and always acquire it before creating or releasing a CAMetalDrawable.