sokol: macOS/Metal: currentDrawable can return null, freezing the render loop.
I’m getting frequent freezing in sokol_gfx.h in my vic20 emulator app running on macOS.
_SOKOL_PRIVATE void _sg_mtl_begin_pass(_sg_pass_t* pass, const sg_pass_action* action, int w, int h) {
....
/* if this is the first pass in the frame, create a command buffer */
if (nil == _sg.mtl.cmd_buffer) {
/* block until the oldest frame in flight has finished */
dispatch_semaphore_wait(_sg.mtl.sem, DISPATCH_TIME_FOREVER); <--- gets stuck here
_sg.mtl.cmd_buffer = [_sg.mtl.cmd_queue commandBufferWithUnretainedReferences];
}
The freezing seems to happen only when there’s other system activity. For example, when I press space in Finder to preview a file the app usually freezes.
Note that I’m running on an ancient macOS version (10.13.6), so this could be a problem in OS/driver, my app or sokol gfx.
Any ideas?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (14 by maintainers)
Commits related to this issue
- sokol_gfx.h Metal: handle currentDrawable == nil (fixes #504) - presentDrawable is skipped if the drawable_cb returns nil - moved the completion handler block up into the first begin-pass of a fram... — committed to hkrn/sokol by floooh 3 years ago
- Squashed commit of the following: commit 9a6237fcdf213e6da48e4f9201f144bcb2dcb46f Author: Andre Weissflog <floooh@gmail.com> Date: Mon Apr 25 14:23:09 2022 +0200 sokol_nuklear.h: fix sg_image ... — committed to relick/sokol by relick 2 years ago
I haven’t found out anything new unfortunately, the problem seems to be down in
[CAMetalLayer nextDrawable]and also happens without MTKView, IFIR I only observed this behaviour when a window gets obscured (which isn’t much of a problem in a single-window-scenario), maybe switching in and out of fullscreen causes a similar behaviour though.