Viewport->ReadPixels() fails in MetalRHI on iOS 15

hey!

i’m attempting to use Viewport->ReadPixels() in what seems like the correct way. It works fine on Windows but I hit an ensure when running on iOS.

it seems that the FTextureRHI that reaches FMetalDynamicRHI::RHIReadSurfaceData() is null on iOS.

is there any other setup i need to do to “prepare” the viewport for this operation?

a section of my code:

TArray<FColor> ViewportColors;
Viewport->ReadPixels(ViewportColors, FReadSurfaceDataFlags(), ReadArea);

i wonder if this is related to this topic from 2016.

i have two related callstacks:

[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: === Handled ensure: ===
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: Ensure condition failed: 0 [File:/Users/build/Build/++UE4/Sync/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalStateCache.cpp] [Line: 2160]
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: NULL texture: EMetalShaderStages 1, Index 0
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: Stack: 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x01ea7a84 FarsightGoProject!FMetalStateCache::EnsureTextureAndType(EMetalShaderStages, unsigned int, TMap<unsigned char, unsigned char, FDefaultSetAllocator, TDefaultMapHashableKeyFuncs<unsigned char, unsigned char, false> > const&) const   [UnknownFile]) 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x01e93548 FarsightGoProject!FMetalStateCache::SetRenderPipelineState(FMetalCommandEncoder&, FMetalCommandEncoder*)   [UnknownFile]) 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x01e89bac FarsightGoProject!FMetalRenderPass::PrepareToRender(unsigned int)   [UnknownFile]) 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x01e8a8d0 FarsightGoProject!FMetalRenderPass::DrawIndexedPrimitive(FMetalBuffer const&, unsigned int, unsigned int, int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)   [UnknownFile]) 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x01e28c68 FarsightGoProject!FMetalRHICommandContext::RHIDrawIndexedPrimitive(FRHIIndexBuffer*, int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)   [UnknownFile]) 
[2023.01.07-12.10.15:878][247]LogOutputDevice: Error: [Callstack] 0x0449d610 FarsightGoProject!FSlateRHIRenderingPolicy::DrawElements(FRHICommandListImmediate&, FSlateBackBuffer&, TRefCountPtr<FRHITexture2D>&, TRefCountPtr<FRHITexture2D>&, TRefCountPtr<FRHITexture2D>&, int, TArray<FSlateRenderBatch, TSizedDefaultAllocator<32> > const&, FSlateRenderingParams const&)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x044ac0d8 FarsightGoProject!FSlateRHIRenderer::DrawWindow_RenderThread(FRHICommandListImmediate&, FViewportInfo&, FSlateWindowElementList&, FSlateDrawWindowCommandParams const&)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x044d5530 FarsightGoProject!TGraphTask<TEnqueueUniqueRenderCommandType<FSlateRHIRenderer::DrawWindows_Private(FSlateDrawBuffer&)::SlateDrawWindowsCommandName, FSlateRHIRenderer::DrawWindows_Private(FSlateDrawBuffer&)::$_33> >::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x01f124ec FarsightGoProject!FNamedTaskThread::ProcessTasksNamedThread(int, bool)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x01f108cc FarsightGoProject!FNamedTaskThread::ProcessTasksUntilQuit(int)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x030d1b54 FarsightGoProject!RenderingThreadMain(FEvent*)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x030e2ab4 FarsightGoProject!FRenderingThread::Run()   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x01fd1bdc FarsightGoProject!FRunnableThreadPThread::Run()   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0x01f78968 FarsightGoProject!FRunnableThreadPThread::_ThreadProc(void*)   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0xf16ef9a4 libsystem_pthread.dylib!_pthread_start()   [UnknownFile]) 
[2023.01.07-12.10.15:879][247]LogOutputDevice: Error: [Callstack] 0xf16eeea0 libsystem_pthread.dylib!thread_start()   [UnknownFile])
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: === Handled ensure: ===
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: Ensure condition failed: TextureRHI [File:/Users/build/Build/++UE4/Sync/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalRenderTarget.cpp] [Line: 227]
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: Stack: 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x01e95ce8 FarsightGoProject!FMetalDynamicRHI::RHIReadSurfaceData(FRHITexture*, FIntRect, TArray<FColor, TSizedDefaultAllocator<32> >&, FReadSurfaceDataFlags)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x056675fc FarsightGoProject!FRenderTarget::ReadPixels(TArray<FColor, TSizedDefaultAllocator<32> >&, FReadSurfaceDataFlags, FIntRect)::$_0::operator()(FRHICommandListImmediate&) const   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x05667c24 FarsightGoProject!TGraphTask<TEnqueueUniqueRenderCommandType<FRenderTarget::ReadPixels(TArray<FColor, TSizedDefaultAllocator<32> >&, FReadSurfaceDataFlags, FIntRect)::ReadSurfaceCommandName, FRenderTarget::ReadPixels(TArray<FColor, TSizedDefaultAllocator<32> >&, FReadSurfaceDataFlags, FIntRect)::$_0> >::ExecuteTask(TArray<FBaseGraphTask*, TSizedDefaultAllocator<32> >&, ENamedThreads::Type)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x01f124ec FarsightGoProject!FNamedTaskThread::ProcessTasksNamedThread(int, bool)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x01f108cc FarsightGoProject!FNamedTaskThread::ProcessTasksUntilQuit(int)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x030d1b54 FarsightGoProject!RenderingThreadMain(FEvent*)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x030e2ab4 FarsightGoProject!FRenderingThread::Run()   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x01fd1bdc FarsightGoProject!FRunnableThreadPThread::Run()   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0x01f78968 FarsightGoProject!FRunnableThreadPThread::_ThreadProc(void*)   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0xf16ef9a4 libsystem_pthread.dylib!_pthread_start()   [UnknownFile]) 
[2023.01.07-12.10.12:747][155]LogOutputDevice: Error: [Callstack] 0xf16eeea0 libsystem_pthread.dylib!thread_start()   [UnknownFile])

any help here would be much appreciated!