mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
ChunkFile: Handle bool in a stable way across platforms
bool is not always guaranteed to be the same size on every platform. On some platforms it may be one byte, on others it can be 8 bytes if the platform dictates it. It's implementation-defined. This can be problematic when it comes to storing this data to disk (it can also be space-inefficient, but that's not really an issue). Also say for some reason you moved your savestates to another platform, it's possible they won't load correctly due to differences in size. This change stores all bools to savestates as if they were a byte in size and handles the loading of them accordingly.
This commit is contained in:
@ -213,6 +213,20 @@ public:
|
||||
DoVoid((void*)&x, sizeof(x));
|
||||
}
|
||||
|
||||
|
||||
void Do(bool& x)
|
||||
{
|
||||
// bool's size can vary depending on platform, which can
|
||||
// cause breakages. This treats all bools as if they were
|
||||
// 8 bits in size.
|
||||
u8 stable = static_cast<u8>(x);
|
||||
|
||||
Do(stable);
|
||||
|
||||
if (mode == MODE_READ)
|
||||
x = stable != 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void DoPointer(T*& x, T* const base)
|
||||
{
|
||||
|
Reference in New Issue
Block a user