Files
UnrealEngineUWP/Engine/Source/Developer/FunctionalTesting/Private/TakeScreenshotAfterTimeLatentAction.cpp
andrew grant 0bf0d10404 - Fix for case where people try to take an automation screenshot during BeginPlay.
Now perform the pre-screenshot flush of loading on the first tick of the latent action and not in its constructor. This addresses cases where BP's attempt to take a screenshot in their BeginPlay event while the world is being created.

- Fix for crash that can happen when a window needs resized after a screenshot is captured.

Don't delete (which leads to restoring the viewport size) on response to the screenshot delegates. Instead queue it by one frame


#jira UE-91269
#rb na
#lockdown Cristina.Riveron

#ROBOMERGE-SOURCE: CL 12788643 in //UE4/Release-4.25/... via CL 12788645 via CL 12788646
#ROBOMERGE-BOT: RELEASE (Release-Engine-Staging -> Main) (v681-12776863)

[CL 12788647 by andrew grant in Main branch]
2020-04-14 20:37:48 -04:00

120 lines
3.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "TakeScreenshotAfterTimeLatentAction.h"
#include "AutomationBlueprintFunctionLibrary.h"
#include "Engine/GameViewportClient.h"
#include "Engine/Engine.h"
#include "EngineGlobals.h"
#include "Misc/AutomationTest.h"
FTakeScreenshotAfterTimeLatentAction::FTakeScreenshotAfterTimeLatentAction(const FLatentActionInfo& LatentInfo, const FString& InScreenshotName, const FString& InNotes, FAutomationScreenshotOptions InOptions)
: ExecutionFunction(LatentInfo.ExecutionFunction)
, OutputLink(LatentInfo.Linkage)
, CallbackTarget(LatentInfo.CallbackTarget)
, ScreenshotName(InScreenshotName)
, Notes(InNotes)
, SecondsRemaining(InOptions.Delay)
, FinishedLoading(false)
, IssuedScreenshotCapture(false)
, TakenScreenshot(false)
, Options(InOptions)
{
}
FTakeScreenshotAfterTimeLatentAction::~FTakeScreenshotAfterTimeLatentAction()
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.RemoveAll(this);
}
void FTakeScreenshotAfterTimeLatentAction::OnScreenshotTakenAndCompared()
{
TakenScreenshot = true;
}
void FTakeScreenshotAfterTimeLatentAction::UpdateOperation(FLatentResponse& Response)
{
if (!FinishedLoading)
{
UAutomationBlueprintFunctionLibrary::FinishLoadingBeforeScreenshot();
FinishedLoading = true;
}
if ( !TakenScreenshot )
{
if ( !IssuedScreenshotCapture )
{
UAutomationBlueprintFunctionLibrary::FinishLoadingBeforeScreenshot();
SecondsRemaining -= Response.ElapsedTime();
if ( SecondsRemaining <= 0.0f )
{
UObject* Caller = CallbackTarget.IsValid() ? CallbackTarget.Get() : nullptr;
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.AddRaw(this, &FTakeScreenshotAfterTimeLatentAction::OnScreenshotTakenAndCompared);
if ( UAutomationBlueprintFunctionLibrary::TakeAutomationScreenshotInternal(Caller, ScreenshotName, Notes, Options) )
{
IssuedScreenshotCapture = true;
}
else
{
//TODO LOG FAILED SCREENSHOT
TakenScreenshot = true;
}
}
}
}
else
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.RemoveAll(this);
Response.FinishAndTriggerIf(true, ExecutionFunction, OutputLink, CallbackTarget);
}
}
#if WITH_EDITOR
FString FTakeScreenshotAfterTimeLatentAction::GetDescription() const
{
return FString::Printf(TEXT("Take screenshot named %s after %f seconds"), *ScreenshotName, SecondsRemaining);
}
#endif
FWaitForScreenshotComparisonLatentAction::FWaitForScreenshotComparisonLatentAction(const FLatentActionInfo& LatentInfo)
: ExecutionFunction(LatentInfo.ExecutionFunction)
, OutputLink(LatentInfo.Linkage)
, CallbackTarget(LatentInfo.CallbackTarget)
, TakenScreenshot(false)
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.AddRaw(this, &FWaitForScreenshotComparisonLatentAction::OnScreenshotTakenAndCompared);
}
FWaitForScreenshotComparisonLatentAction::~FWaitForScreenshotComparisonLatentAction()
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.RemoveAll(this);
}
void FWaitForScreenshotComparisonLatentAction::OnScreenshotTakenAndCompared()
{
TakenScreenshot = true;
}
void FWaitForScreenshotComparisonLatentAction::UpdateOperation(FLatentResponse& Response)
{
if ( TakenScreenshot )
{
FAutomationTestFramework::Get().OnScreenshotTakenAndCompared.RemoveAll(this);
Response.FinishAndTriggerIf(true, ExecutionFunction, OutputLink, CallbackTarget);
}
}
#if WITH_EDITOR
FString FWaitForScreenshotComparisonLatentAction::GetDescription() const
{
return FString(TEXT(""));
}
#endif