Texture Generating issue

I found the method below to generate and then export texture via coding, but it just works for power of 2 texture sizes



GenerateTexture(int textureWidth, int textureHeight, uint8* inputImage, FString textureName)
{
UPackage* Package = CreatePackage(NULL, TEXT("/Game/"));
UTexture2D* NewTexture = NewObject<UTexture2D>(Package, FName(textureName), RF_Public | RF_Standalone | RF_MarkAsRootSet);
NewTexture->AddToRoot();
NewTexture->PlatformData = new FTexturePlatformData();
NewTexture->PlatformData->SizeX = textureWidth;
NewTexture->PlatformData->SizeY = textureHeight;
NewTexture->Source.Init(textureWidth, textureHeight, 1, 1, ETextureSourceFormat::TSF_G8, inputImage);
NewTexture->UpdateResource();
Package->MarkPackageDirty();
}


for non-power of 2 texture size it gives error below :

Assertion failed: SourceImageData.SizeX == ScaleFactor * DestImageData.SizeX || DestImageData.SizeX == 1 [File:\Build++UE4+Licensee\Sync\Engine\Source\Developer\TextureCompressor\Private\TextureCompressorModule.cpp] [Line: 428]

Did you ever figure out how to fix it? :thinking: