I have a multithreaded application. All the rendering is performed on a different thread than the main thread.
- The device and the different CommandQueue are created on the main thread.
- The RenderThread will create and commit new commandBuffers.
- The swap chain image are acquired on the RenderThread by calling nextDrawable on the CAMetalDrawable via the main UIWindow.
Code:
CAMetalLayer *layer= (CAMetalLayer*)uiView.layer;
setRenderTarget(layer.texture)
This triggers a weird crash on iOS when committing an empty commandbuffer (just a simple clear operation).
[m_command_buffer commit];
Note this seems to work fine on macOS using NSView instead. Is it something to be expected? how should we acquire the swap chain image and call the final [commandBuffer commit] on a multithreaded system?
apple documentation: https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Cmd-Submiss/Cmd-Submiss.html#//apple_ref/doc/uid/TP40014221-CH3-SW6
At first I thought it was a memory issue but: xcode gauge is in the green with 3gb left, I also added the increase memory limit permission. The crash is located when commit is called, if I comment it I can continue running my main loop.