MTKView not showing on some iOS 12 devices

We are getting user reports where the MTKView is not showing on their devices. All of them are running iOS versions <= 12.3. We did not manage to reproduce the issue. Users are still able to export (which indicates that layer.nextDrawable().texture is still accessible). As the MTKView is the main interface of the app, it makes it useless.

Our code is similar to this code sample, except that we render textures instead of colors.

It started happening after an update of our app where we de-allocate the MTKView every time the user goes back to the main menu of the app.

We would appreciate any input on how to find a fix regarding this issue.
So there are dozens of possibilities here: But a few come to mind.

1) Are you responding to drawableSizeWillChange: and updating the data sent to the vertex shader? In the sample you referenced, app changes the _viewportSize iVar to the new size passed into that method. The vertex shader depends on this size, so if the incorrect size get's sent, then the triangle(s) won't get rendered properly.

2) Are you responding to drawInMTKView properly? Or rather are you even getting calls to that method? By default, this is called at a regular interval for your app to execute the Metal commands to draw. But if that's not getting called that nothing will render. This could happen because you've paused the MTKView.

3) Are you resizing the drawable yourself by modifying the drawableSize property of the view? Is autoResizeDrawable ever set to false? This could be related and lead to scenerio in 1) if the size isn't set properly.

4) How are you loading the texture data? What do you do with the texture when you destroy the view? Perhaps the image isn't getting loaded so Metal can't draw it.

5) Something to do with how the view is set in the window. I'm less familiar with this particular aspect of our SDK since I generally work on Metal, but you should probably check if it's getting set properly. One thing you can try is clearing the screen to red with Metal and setting the background colors of your view to something else. If users see red, then you know that this is truly a Metal rendering problem. If it's the background color then it means the view isn't set properly and so even though you may be rendering correctly, the view's contents are getting to the scree.

Some more context (i.e. code) would help narrow this down.
Thank you very much for your thorough answer.

I'd like to first point out that our code works well on all devices > iOS 12.3.

1) We're not overriding drawableSizeWillChange
2) We're currently adding logs to ensure the affected devices are calling the draw method. But on workind devices it's called properly. The MTKView is not paused
3) We're setting drawableSize manually and we always set autoResizeDrawable to false.
4) We're loading texture data with MTKTextureLoader. We're not doing anything in particular with the texture when destroying the view
5) This might be it, as we had inconsistencies with constraints in the past

We'll investigate a bit more thanks to your ideas, and if the issue keeps appearing I'll put together a simplified version of our code. Thanks again!


A point about 1) and 3) above because they are related:

As mentioned previously: "In the sample you referenced, the AAPLRenderer class changes the _viewportSize iVar to the new size passed into that method. The vertex shader depends on this size, so if the incorrect size get's sent, then the triangle(s) won't get rendered properly."

So you need to do that step whether or not you set the drawable size manually; ensure you update any values sent to the shaders which depend on the drawable size you've set.


MTKView not showing on some iOS 12 devices
 
 
Q