Serialization to archive can corrupt source data

When serializing data into an archive that performs byte swapping, the archiver will apply byte swapping also to the source data. This is likely not the intended behavior?

Tested by serializing a float to an FBufferArchive with ArForceByteSwapping = true, but this probably applies also to archives that are marked persistent and used on big-endian systems.

Edit: I just realized that the above happens on little-endian systems if the archive is marked as persistent; UE seems to use network byte order as it’s storage/replication endianness.

Repro

Place this in a tick function or such:

float foo = 1234.56789e+20;
FBufferArchive ar;

UE_LOG( LogTemp, Warning, TEXT( "%g" ), foo );

ar << foo;
UE_LOG( LogTemp, Warning, TEXT( "%g" ), foo );

ar.ArForceByteSwapping = true;
ar << foo;
UE_LOG( LogTemp, Warning, TEXT( "%g" ), foo );

Output:

LogTemp:Warning: 1.23457e+023

LogTemp:Warning: 1.23457e+023

LogTemp:Warning: -2.89951e+015

Hey -

I was able to reproduce the behavior you mentioned and have entered a bug report (UE-23374) for further investigation.

Cheers