Update3:
Special thanks to Nick Penwarden,
I’ve now been able to create my own custom screenshot saving system with my custom gameviewport client.
I’ve posted a tutorial for the community here where I give the entire code I"m using for my auto-filename generating screenshot saving feature.
Update2: Ahhhh
baseengine.ini
[/Script/Engine.Engine]
ConsoleClassName=/Script/Engine.Console
GameViewportClientClassName=/Script/Engine.GameViewportClient
Update: All I need to know now is how to use a custom viewport class with my project Is that in a config file somewhere?
Dear Friends at Epic,
Hi there!
I am trying to save an image of the viewport to a FColor array to later add it to a save file for “snap shots” of save games.
I am sure the buffer I’m allocating is large enough, as I am only trying to pixels for a small part of the screen (0,0,500,500) compared to buffer size of 1280 x 720
I dont know if Rocket is running DX11 or not, and if that has something to do with the error.
I am calling this functions outside of the Editor, via the right click context menu play game option. (crash occurs if called from PIE as well)
Here is my code:
header file
TArray RV_ColorBuffer;
I have tested that the viewport is being found correctly because the ClientMessage returns correct viewport size (x= 1280 y= 720),
which I then use to allocate the FColor array.
void Thefunction()
{
//~~~ Found Viewport Client? ~~~
if(!VictoryViewPortClient) return;
//~~~~ Viewport client ~~~
if (!VictoryViewport) return;
//get viewport size
FVector2D viewportSize;
VictoryViewPortClient->GetViewportSize(viewportSize);
//output text
FString text = "x= ";
text += FString::FromInt(viewportSize.X);
text += "y= ";
text += FString::FromInt(viewportSize.Y);
ClientMessage(text);
//~~~ Invalid View Port Size ~~~
if (viewportSize.X <= 0 || viewportSize.Y <= 0) return;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~ Empty Color Buffer ~~~
RV_ColorBuffer.Empty();
//~~~~~~~~~~~~~~~~~~~~~~~~
//~~~ Reallocate Buffer ~~~
//add uninitialized does not call constructor on the TArray type
//do not use with non-simple data types
RV_ColorBuffer.AddUninitialized( viewportSize.X * viewportSize.Y );
//~~~~~~~~~~~~~~~~~~~~~~~~
//Get Screen Shot!
if (!VictoryViewport->ReadPixels(RV_ColorBuffer, FReadSurfaceDataFlags(), FIntRect(0, 0, 500, 500)))
{
ClientMessage("Failed to ReadPixels");
return;
//~~~~~~~~~~~~~~~~~~~~~~~~~
}
}
Here is the error message:
PS: using AddZeroed() instead of uninitialized did not cause any change, and it is definitely just the ReadPixels part that is causing crash, buffer allocates just fine
PSS: ReadFloat16Pixels() yields same behavior of thread exception, even with properly (as far as I know) pre-initialized buffer being supplied