我用的是在游戏线程给渲染线程发消息 ENQUEUE_RENDER_COMMAND这个宏 调用了RHICommandList里的CopyTexture,将视口的Texture RHI拷贝到渲染目标2D的Texture RHI里,这个时候如果编辑器界面出现大幅度波动,例如关闭内容浏览器,则会导致崩溃。
FRHITexture* Target = GEditor->GetActiveViewport()->GetRenderTargetTexture();
ENQUEUE_RENDER_COMMAND(ReadSurfaceData)(
[this, Target](FRHICommandListImmediate& RHICmdList)
{
if (!RHICmdList.IsStalled())
{
RHICmdList.CopyTexture(Target, RenderTarget2D->GetResource()->GetTexture2DRHI(), FRHICopyTextureInfo{});
}
}
);
FlushRenderingCommands();