My iPad app has a View that uses a Metal shader as described here.
#include <metal_stdlib>
using namespace metal;
[[ stitchable ]] half4 borderField(float2 position, half4 currentColor, float2 size, half4 newColor) {
assert(size.x >= 0 && position.x <= size.x);
assert(size.y >= 0 && position.y <= size.y);
// Compute distance to border
float dt = size.y - position.y; // Distance to top
float db = position.y; // Distance to bottom
float dl = position.x; // Distance to left
float dr = size.x - position.x; // Distance to right
float minDistance = min(min(dt, db), min(dl, dr));
float r = minDistance + 1.0;
float strength = 1.0 / sqrt(r);
return half4(newColor.rgb, strength);
}
It is applied to my View using the following modifier:
.colorEffect(ShaderLibrary.fields(.floatArray(viewModel.floatArray)))
The app can use any device orientation.
If I launch it in portrait orientation, the View is displayed correctly:
If I turn the simulator left and launch the app in landscape orientation, the following error is logged:
RBLayer: unable to create texture: BGRA8Unorm, [8.196, 5.200]
and the View is not colored:
If I turn the simulator back to portrait mode while the app is running, the View is again colored correctly.
However, if I turn it left again while the app is running, I get once more the same error, but the View looks now differently:
I don't have experience in Metal programming, and I have no idea what is wrong.
There are 2 posts that report a similar error, but apparently they do not apply to my case: This one, and this one.
Any suggestions?


