TextureRHI not inited while making Game Screenshot

Hello,

I’m trying to make a screenshot in game mode, and I always get this error that I cannot figure out.
I have searched far and wide, rei nstalled drivers and graphics modes, opengl, dx11, dx12 changes and development/shipping compiles. Always the same error.

The practically same code generates a in editor screenshot without any problems.
Anyone have any idea what to try? I’m stuck without new options, and trying to figure out why in editor is working so simply out of the box, yet game mode has such trouble with generating an image.

This is the code:

UGameViewportClient* GameViewport = GEngine->GameViewport;
FViewport* Viewport = GameViewport->Viewport;

FIntRect Rect(0, 0, Viewport->GetSizeXY().X,  Viewport->GetSizeXY().Y);
TArray<FColor> ViewportPixels;
GetViewportScreenShot(Viewport, ViewportPixels, Rect);

This is the crash stack

Error: === Handled ensure: ===
Error: Ensure condition failed: TextureRHI [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/D3D12RHI/Private/D3D12RenderTarget.cpp] [Line: 1190]
Error: Stack:
Error: [Callstack] 0x00007fff544e62d9 UE4Editor-D3D12RHI.dll!<lambda_9645d233a10e2c8fecc81f84248ee627>::operator()() [D:\Build\++UE4\Sync\Engine\Source\Runtime\D3D12RHI\Private\D3D12RenderTarget.cpp:1190]
Error: [Callstack] 0x00007fff54477488 UE4Editor-D3D12RHI.dll!FD3D12DynamicRHI::RHIReadSurfaceData() [D:\Build\++UE4\Sync\Engine\Source\Runtime\D3D12RHI\Private\D3D12RenderTarget.cpp:1190]
Error: [Callstack] 0x00007fffdc13ccff UE4Editor-RHI.dll!FRHICommandListImmediate::ReadSurfaceData() [D:\Build\++UE4\Sync\Engine\Source\Runtime\RHI\Public\RHICommandList.h:4426]
Error: [Callstack] 0x00007fff99ccfa92 UE4Editor-Engine.dll!TEnqueueUniqueRenderCommandType<`FRenderTarget::ReadPixels'::`2'::ReadSurfaceCommandName,<lambda_67c857c661c8c2831feaa2e800c6a805> >::DoTask() [D:\Build\++UE4\Sync\Engine\Source\Runtime\RenderCore\Public\RenderingThread.h:195]
Error: [Callstack] 0x00007fff99ce5c6d UE4Editor-Engine.dll!TGraphTask<TEnqueueUniqueRenderCommandType<`FRenderTarget::ReadPixels'::`2'::ReadSurfaceCommandName,<lambda_67c857c661c8c2831feaa2e800c6a805> > >::ExecuteTask() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:849]
Error: [Callstack] 0x00007fff9b8687d8 UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:692]
Error: [Callstack] 0x00007fff9b868aa3 UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:587]
Error: [Callstack] 0x00007fffdd2af892 UE4Editor-RenderCore.dll!RenderingThreadMain() [D:\Build\++UE4\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:341]
Error: [Callstack] 0x00007fffdd2b53d4 UE4Editor-RenderCore.dll!FRenderingThread::Run() [D:\Build\++UE4\Sync\Engine\Source\Runtime\RenderCore\Private\RenderingThread.cpp:473]
Error: [Callstack] 0x00007fff9bd504db UE4Editor-Core.dll!FRunnableThreadWin::Run() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:86]
Error: [Callstack] 0x00007fff9bd47eb0 UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:35]
Error: [Callstack] 0x00007fffe8c77034 KERNEL32.DLL!UnknownFunction []
Error: [Callstack] 0x00007fffe947cec1 ntdll.dll!UnknownFunction []