How to copy an Array saved as TUniquePtr?

Schrello
Fri, 16 Dec 2022 13:41:43 +0000
C++

Hey,

I am using TUniquePtr<uint8[]> PixelBuffer; to store pixel data of a texture as an array. Like iUltimateLP does it in his code.

The creation and drawing of the texture is working so far. (as shown in the picture below)

Now I am trying to create a copy of that array using a for loop. (I am using a for loop because I want to extract just parts of the texture later on. But just for demonstration I copy the array completly in this example.)

SIZE_T PartBufferSize = WorldTextureWidth * WorldTextureHeight * DYNAMIC_TEXTURE_BYTES_PER_PIXEL;
	TUniquePtr<uint8[]> PartPixelBuffer = MakeUnique<uint8[]>(PartBufferSize);

	for (int i = 0; i < WorldTextureHeight *WorldTextureWidth * DYNAMIC_TEXTURE_BYTES_PER_PIXEL; i++) {

		PartPixelBuffer[i] = PixelBuffer[i];
	}

The pixels after copying are mixed up and the picture is different every time I execute this code. (as shown on the picture below)

What am I doing wrong?

1 post - 1 participant