Can't use binaries from other builds
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.
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.
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);
Have you tried PortableBinary archives?
Yes, it didn't have any effect.
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.
There might be uint32_fast etc. They have some leway on size, so they might be the culprit. Let me check and report back.
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