TSharedPtr<IImageWrapper->GetRaw() problem! Unreal 4.25

Unreal Engine 4.25

I’m getting this compile error:



error C2664: 'bool IImageWrapper::GetRaw(const ERGBFormat,int32,TArray<uint8,FDefaultAllocator> &)': cannot convert argument 3 from 'const TArray<uint8,FDefaultAllocator> *' to 'TArray<uint8,FDefaultAllocator64> &'


I noticed there is an overloaded function for GetRaw built in to the engine that makes it either look for a TArray OR a TArray64

And for the life of me I can’t get this to compile. I’ve tried using TArray64 for “BinaryArray” and “RawData” variables, but it still compiled with the same error…

What am I missing about this?.. Most likely I don’t understand something, but I also wonder if this is a bug/issue with 4.25…



UE_LOG(LogTemp, Log, TEXT("Try to load a png!"));

FString PngFile = FString(TEXT(""));
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
//IImageWrapperPtr PNGImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
//^^^ Noticed this was depreciated! It suggested using the next line instead.
TSharedPtr<IImageWrapper> PNGImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
TArray<uint8> BinaryArray;

if(FFileHelper::LoadFileToArray(BinaryArray, *PngFile))
{
UE_LOG(LogTemp, Log, TEXT("LoadFileToArray() success"));

if(PNGImageWrapper.IsValid())
{
UE_LOG(LogTemp, Log, TEXT("its valid, keep going"));
const TArray<uint8>* RawData = NULL;

if(PNGImageWrapper->GetRaw(ERGBFormat::BGRA, 8, RawData))
{
UE_LOG(LogTemp, Log, TEXT("GetRaw success keep going"));
}
}

}


if I comment out the GetRaw() line and the whole if statement my UE_LOG shows:



Try to load a png!
LogTemp: LoadFileToArray() success
LogTemp: its valid, keep going


Alternatively I might be missing something dumb with pointer/address stuff when passing this in? But it is strange that it’s getting confused about what type of argument it is with that overload funciton situation.

Look at the declaration of your third parameter:


const TArray<uint8>* RawData

Reading it from right to left: RawData is a pointer to a TArray of uint8 that is constant.

bool IImageWrapper::GetRaw()'s third parameter is a reference. Drop that * from RawData’s declaration, and probably the const, as well.

Thanks! I had to remove const and * for it to compile but it does indeed compile now. Got to go deeper into some c++ tutorials on to better understand pointers, refs, polymorphism… still learning, thanks a lot!

Not a problem. We all gotta start somewhere. Glad you’re back on track.

This type is an abstract class and I use it with a hint that I am using an incomplete type. Excuse me, how should be solved here .
thank you.

User113
You mean a U Class ?object

He made this in Actor Class, the way it’s structured, it has no function at all.
He probaly included it into begin play?
In UClass the if statements outside functions will give errors so you got to find a function to hold everything and that is not easy at least from my point of view.

I can understand function parameters to a certain extent, if they are fstrings ints, but beyond that where you throw pointers inside a parameter ( ) section , or it’s a list of parameters with other elements, a very dynamic type of thing. I could get confused in it.

Here is an example of such function in a UClass

static TFuture<UTexture2D*> LoadImageFromDiskAsync(UObject* Outer, const FString& ImagePath, TFunction<void()> CompletionCallback);

It looks really really bad, if you just take the code it will compile, but if try to split it into sections, you’re in for some “Choop”

You got to return all of that with return statement, where it really gets annoying.
I got errors of incompletion that I did not return all of the parametric values stated in there, but I did go over them, but still got errors.

Another Problem is this, if you try to go direct and ditch the if statements.
You end up doing just this.
FFileHelper::LoadFileToArray(BinaryArray, *PngFile)
You will get an error if you try this in a UClass, it’s a strange error saying you are redeclarring FFileHelper , when you are not, because this is the first mention where you are putting it, it’s a bug of some sort I guess because why does it not give errors in an AActor class when you do the same there.

A nice example for all of us would be good on how to do this in a UClass.