Hello,
I am trying to read pixel from RenderTarget In SceneCaptureComponent2D. but when I call CaptureScene() in loop, I found that memory was occupied much a lot and never free.
My Code is:
bool HasCapture = false;
TArray<AActor*> Actors = GWorld->GetCurrentLevel()->Actors;
TArray<ASceneCapture2D*> Captures;
for (int i = 0; i < Actors.Num(); i++)
{
if (Actors[i]->IsValidLowLevel())
{
ASceneCapture2D* TempCapt = Cast<ASceneCapture2D>(Actors[i]);
if (TempCapt != nullptr)
{
TempCapt->GetCaptureComponent2D()->bCaptureEveryFrame = false;
TempCapt->GetCaptureComponent2D()->bCaptureOnMovement = false;
Captures.Add(TempCapt);
HasCapture = true;
}
}
}
if (!HasCapture) { return; }
for (int32 i = 0; i < 1000; i++)
{
Captures[0]->GetCaptureComponent2D()->CaptureScene();
}
When I Open Project, memory is:
After I Execute this Code, memory is:
I am not very familiar with C++, So I don’t know what went wrong.
And then I test code in Blueprint, It also happened.
blueprint:
So I will really appreciate it if someone told me how to deal with it.