Crash on MTLDebugCommandBuffer lockPurgeableObjects in MacOS 12

We see strange crashes when running our app since macOS 12 Beta (but still on macOS 12.0.1). We have not been able to fully identify the issue but it seems to happen on continue video playback in an AVPlayer, sometimes due to background, sometimes due to continue playback directly. Xcode points to some code in the libsystem_kernel.dylib (seems different every time and never in our own code)

The log will show:

-[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion 'MTLResource 0x600002293790 (label: (null)), referenced in cmd buffer 0x7f7b2200a000 (label: (null)) is in volatile or empty purgeable state at commit'

-[MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion 'MTLResource 0x600002293790 (label: (null)), referenced in cmd buffer 0x7f7b2200a000 (label: (null)) is in volatile or empty purgeable state at commit'

We tried finding the object 0x600002293790 and 0x7f7b2200a000 but this gave no additional information as to why the app crashes.

We are using a custom VideoCompositor: AVVideoCompositing and initialise the CIContext for the work done here with these options:

if let mtlDevice = MTLCreateSystemDefaultDevice() 
    let options: [CIContextOption : Any] = [
        CIContextOption.useSoftwareRenderer: false,
        CIContextOption.outputPremultiplied: false,
    ]
    let context = CIContext(mtlDevice: mtlDevice, options: options)
}

Not sure this is an Xcode 13 debug issue? a macOS 12.0.1 Monterey issue? or an actual issue as we have not seen it crash when not using Xcode to build our app giving this information. But we have seen strange crashes on Audio/Video threads that we could not trace back to our code as well.

The crash has never occurred on Xcode 12 or on macOS Big Sur during previous testing.

Any information as to locating the source of the issue or a solution would be awesome.

Likely if the crash appears at random points in the code, you actually have a threading issue, and a background thread is crashing somewhere. I think a lot of AV Video code makes heavy use of multi threading.

Any ideas as too pinpointing this type of issues? Since we can't actively replicate it but it happens random like 2/3 times a day while working on our application. How ever once the crash occurs we have no idea how to figure our who started the issue. We have seen these messages before the crash. Not sure they always happen though. Will check the next time it happens:

2021-09-28 15:53:06.503135+0200 ****[48028:857651] [] [15:53:06.503] FPSupport_GetDisplayRefreshInformation signalled err=-12780 (kCMBaseObjectError_ParamErr) (CGDisplayModeGetRefreshRate returned 0) at FigPlayerSupport.m:3198

2021-09-28 15:53:06.548090+0200 ****[48028:857658] [] [15:53:06.548] customVideoCompositor_CopyProperty signalled err=-12784 (kFigBaseObjectError_PropertyNotFound) (unrecognised property) at FigVideoCompositor_Custom.c:581

While going through some screenshots of the crash I actually found one more that says something about Screen layout change with no seed change. Since I can't edit the original question anymore, or upload an image I'm not sure how to get you the full log details.

Crash on MTLDebugCommandBuffer lockPurgeableObjects in MacOS 12
 
 
Q