hi, i am a newer doing project on ue4.5
Now i need to render the cube to a image. And the render texture can not use MSAA, So i need to render the vireport six times and capture viewport and merge the six image to a cubemap.
I change new render window to 1024 * 1024 mode(cubemap must be width == height).
But i found that FViewPort::ReadPixels crash while play on “standalone Game” mode and runs well on “Selected Viewport” mode.(“Selected Viewport” mode could not resize window to 1024 * 1024)
why FViewPort::ReadPixels crash? the crash message is: counld not located import “SetCheckUserInterruptShared” on dbgeng.dll
My code like this:
UWorld* world = GetWorld();
if (world)
{
UGameViewportClient* viewportClient = GEngine->GameViewportForWorld(world);
FSceneViewport* svp = viewportClient->GetGameViewport();
TArray<FColor> left;
svp->ReadPixels(left, FReadSurfaceDataFlags());
}
And i confirm the svp not NULL.
My os is windows 8.
Sorry for my poor english.
Only Call ReadPixels inside of GameViewport:: Draw
I had this issue during the Beta, you can only call ReadPixels inside of the Draw function of Viewport class!
So this means you need to use your own custom GameViewport class and override Draw()
For your entertainment is my example of using ReadPixels to take a screenshot!
Anywhere in your code base you can set the bool to true to trigger a screenshot on the next Draw call.
Enjoy!
//Draw
void USolusViewportClient::Draw(FViewport * Viewport, FCanvas * SceneCanvas)
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//this line is reaalllly important
Super::Draw(Viewport, SceneCanvas);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//UE_LOG(Victory,Warning,TEXT("VICTORY GAME VIEWPORT Ticking!"));
//Take Screen shot?
if (VictoryDoScreenShot)
{
VictoryDoScreenShot = false;
VictoryTakeScreenShot();
}
}
So inside of VictoryTakeScreenShot() is where you’d make the call to ReadPixels()
But this setup allows you to trigger a screenshot from anywhere!
.h
's what the .h looks like.
```
#pragma once
#include "SolusViewportClient.generated.h"
UCLASS()
class USolusViewportClient : public UGameViewportClient
{
GENERATED_UCLASS_BODY()
//set this from anywhere to trigger screenshot inside of Draw()
public:
//Triggers ScreenShot
bool VictoryDoScreenShot;
//protected because must only be run from Draw() or causes crash
protected:
void VictoryTakeScreenShot();
virtual void Draw(FViewport* Viewport,FCanvas* SceneCanvas) override;
};
```
DefaultEngine.ini Config
You have to tell UE4 to use your custom viewport class:
As said, try doing it within a Draw function, normally accessing view stuff requires a valid view which is only valid while drawing. This applies to accessing the view or the canvas when you are doing stuff with the HUD.
Are you calling it still from a tick or a draw call? From the place it crashes it seams that the Texture is not valid and its GetResource() returns a null pointer, could you put a breakpoint there or a log checking for null both for the texture and it’s resource?