Download

FImageUtils::CreateTexture2D crashes in packaged build

Trying to convert a raw RGBA image (built at runtime procedurally in C++) to a UTexture2D using FImageUtils::CreateTexture2D. Works great in editor. But when I do a packaged build and run on PC…


LowLevelFatalError [File:Unknown] [Line:239]
ConstructTexture2D not supported on console.

The code…



TArray<FColor> data;

...

FCreateTexture2DParameters params;
params.bUseAlpha = true;
params.TextureGroup = TEXTUREGROUP_16BitData;
UTexture2D * texture = FImageUtils::CreateTexture2D(
    w, h, data, outer, TEXT("SgTexture"),
    EObjectFlags::RF_Public | EObjectFlags::RF_Transient,
    params );



Is there an alternate way (in C++) to create a texture from raw RGBA data?

Solved using CreateTransient and lock/copy data…


 unrealTexture = UTexture2D::CreateTransient( w, h, PF_B8G8R8A8 );
void * TextureData = unrealTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
FMemory::Memcpy( TextureData, data.GetData(), 4*w*h );
unrealTexture->PlatformData->Mips[0].BulkData.Unlock();
unrealTexture->UpdateResource();