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

Most upvoted comments

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.