ReadPixels crashing on TickComponent

I’m writing a plugin that defines an actor with a component that gets a copy of the screen from the viewport every 10 seconds using the ReadPixels method.

While running it in the editor it works just fine but when running from a standalone package or exe it crashes with the message “Rendering thread exception”

According to the code, when ReadPixels is called the engine throws a command to read the pixels onto the the que for the rendering thread then waits for the rendering thread to clear.

In the editor it finishes in just a couple wait cycles and is fine. When running the game by itself it takes dozens of cycles then it says that the rendering thread crashed without giving any more detail than that.

I was using 4.0.1 and saw in some of the changenotes that they mentioned a fix to screenshot capturing, so I updated to 4.2.1 but still got the same issue.

Is ReadPixels not supposed to be called during a tick operation? If so, why does it work in the editor and is there an alternative I can use? If not, where can I safely call it from?

#Only ReadPixels in Draw Loop

You should only be calling ReadPixels from within the Viewport class inside of the Draw Loop!

I got your same crash during the Beta and the below is my solution that works to this day.

#The Draw Loop

//Draw
void UVictoryGameViewport::Draw(FViewport * Viewport, FCanvas * SceneCanvas)
{

#Bool Flag

I use a boolean flag to trigger a read pixels whenever I want, still allowing it to run from inside the Draw Loop

//Draw
    void UVictoryGameViewport::Draw(FViewport * Viewport, FCanvas * SceneCanvas)
    {
    //Take Screen shot?
    	if (VictoryDoScreenShot)
    	{
    		VictoryDoScreenShot = false;
    		VictoryTakeScreenShot();	//ReadPixels is used in here
    	}

I set VictoryDoScreenShot = true from anywhere in my code base

enjoy!

Rama

Thank you.

Do you know why the crash happens, and why it works in editor but not standalone? Is UVictoryGameViewport a custom class that you overwrite the GameViewportClass on GEngine with?