cereal icon indicating copy to clipboard operation
cereal copied to clipboard

Can't use binaries from other builds

Open enginmanap opened this issue 6 years ago • 7 comments

Hi,

I have a game engine, and I am using Cereal to serialize model files to binary. I assume reading files on another system with same endianness should be no problem, but it is. Files created on Windows works on MacOS but not on Linux.

Cereal is bundled with source code, and engine has no path seperation for different OSes.

Another note is, files created by debug builds are not same as files created by release builds. Loading files from debug build causes issues because of wrong values on some variables.

Linux and Windows tests are run on same PC to minimize possible causes.

From To Result
Windows Debug Windows Release Wrong values
Windows Release MacOS Release OK
Windows Release Linux Release Can't load (Bad malloc)
Linux Release Windows Release Can't Load (Bad Malloc)

PS: Bad malloc issues are caused by trying to allocate huge std::vectors, the size of std::vectors read wrong on load.

enginmanap avatar Feb 03 '19 12:02 enginmanap

Do you mind sharing how you are serializing to binary? If you are writing to a file with an ofstream, make sure that you specify the std::ios_base::binary flag when doing so - I've had experiences on Windows where the lack of that flag caused the output to be not quite as expected.

AzothAmmo avatar Feb 04 '19 04:02 AzothAmmo

serialize:

std::ofstream os(newName, std::ios::binary);
cereal::BinaryOutputArchive archive( os );
archive(*modelAsset);

deserialize:

std::ifstream is(files[0], std::ios::binary);
cereal::BinaryInputArchive archive(is);
ModelAsset* ma = new ModelAsset();
archive(*ma);

enginmanap avatar Feb 04 '19 09:02 enginmanap

Have you tried PortableBinary archives?

Devacor avatar Mar 21 '19 23:03 Devacor

Yes, it didn't have any effect.

enginmanap avatar Mar 22 '19 06:03 enginmanap

Are you using fixed width integer, e.g. uint64_t or are you maybe using unsigned long which just happens to have a different size on different operating systems? It wouldn't explain the windows -> windows debug problem though.

h-2 avatar May 06 '19 08:05 h-2

There might be uint32_fast etc. They have some leway on size, so they might be the culprit. Let me check and report back.

enginmanap avatar May 06 '19 09:05 enginmanap

Got the same problem with the long double type. Was serializing long double on arm64 macOS, where the size of it is 8 bytes, and then trying to deserialize on x86_64 Linux, where the size of it is 16 bytes

yurideon avatar Mar 30 '24 03:03 yurideon