I want to update several video streams to UTexture2D use UpdateTextureRegions, it will crash.
only update one video stream is fine.
void AVideoStreams::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
int Width = 640, Height = 480;
if (!DebugStreamTexture1)
{
DebugStreamTexture1 = UTexture2D::CreateTransient(Width, Height);
DebugStreamTexture1->UpdateResource();
DebugStreamTexture2 = UTexture2D::CreateTransient(Width, Height);
DebugStreamTexture2->UpdateResource();
DebugStreamTexture3 = UTexture2D::CreateTransient(Width, Height);
DebugStreamTexture3->UpdateResource();
DebugStreamTexture4 = UTexture2D::CreateTransient(Width, Height);
DebugStreamTexture4->UpdateResource();
}
static uint8_t *StaticData = nullptr;
if (!StaticData)
StaticData = new uint8_t[4 * Width * Height];
FDataCleanupFunc CleanupFunc =
[](uint8 *SrcData, const FUpdateTextureRegion2D *Regions) -> void
{
delete Regions;
};
FUpdateTextureRegion2D *Region1 = new FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);
DebugStreamTexture1->UpdateTextureRegions(0, 1, Region1, 4 * Width, 4,
StaticData, CleanupFunc);
FUpdateTextureRegion2D *Region2 = new FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);
DebugStreamTexture2->UpdateTextureRegions(0, 1, Region2, 4 * Width, 4,
StaticData, CleanupFunc);
FUpdateTextureRegion2D *Region3 = new FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);
DebugStreamTexture3->UpdateTextureRegions(0, 1, Region3, 4 * Width, 4,
StaticData, CleanupFunc);
FUpdateTextureRegion2D *Region4 = new FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);
DebugStreamTexture4->UpdateTextureRegions(0, 1, Region4, 4 * Width, 4,
StaticData, CleanupFunc);
}