Game crash on full screen capture

Hi guys…
I’m working on a screen capture and processing function, where I am doing a screen capture via FScreenshotRequest::RequestScreenshot(true) and doing some simple processing with the attached delegate.

Everything is working hunky dory on a windowed game at say 1920 X 1080, but as soon as I go full screen (my screen is 3440 X 1440), the game crashes with no sensible error detected. I am assuming that my graphics card is running out of memory?

Is there any way to rectify this situation for my users?

Here is my basic function…

void USBGameInstance::TakeScreenShot()
{

	if (!UGameViewportClient::OnScreenshotCaptured().IsBound())
	{
		ocv::delegateHandle = UGameViewportClient::OnScreenshotCaptured().AddStatic(&OnScreenCap);

		FScreenshotRequest::RequestScreenshot(true);
	}
}

void USBGameInstance::OnScreenCap(int32 Width, int32 Height, const TArray<FColor>& Bitmap)
{
	int ulx, uly, lrx, lry;
	bool found = false;

	for (int i = 0; i < Width; i++) // crashes at some point in these loops.
	{
		for (int j = 0; j < Height; j++)
		{
			FColor bmp = Bitmap[i + (j * Width)];
			if (bmp.R == 255 && bmp.G == 0 && bmp.B == 255) { // magenta
				ulx = i;
				uly = j;
				found = true;
				break;
			}
		}
		if (found) {
			break;
		}
	}
	found = false;
}

Hello, @

Yes, I’m guessing that your graphics card is running out of memory too, due to the huge “BitMap” array. If you stop and think about it, in the worst case scenario, the last index accessed by the two for loops is “3440 + 1440 * 3440 = 4.957.040” A nearly 5 million index! Crazy stuff…

I would recommend you to read the following article from “Kazimieras” about taking screenshots on UE4:

It’s a pretty well-written article, see if it can help you. I would like to quote a piece of it that goes like:

When dealing with unusually large
container class objects, it’s an
excellent idea to preallocate a memory
block for them. Depending on the
particular container class, adding an
element to the container might cause
the entire container object to be
copied from one block of free memory
to another, longer block so that the
container fits.

Maybe that’s the problem of your solution! Anyway, tell us later if this article helped you!

Cheers!