From 4ae4b241ec312507160c3a9c9d4643af3ae6986e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 Apr 2016 22:22:34 -0400 Subject: [PATCH] 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. --- Source/Core/Common/ChunkFile.h | 14 ++++++++++++++ Source/Core/Core/State.cpp | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index 386880e989..0f177e6761 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -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(x); + + Do(stable); + + if (mode == MODE_READ) + x = stable != 0; + } + template void DoPointer(T*& x, T* const base) { diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index f9542d3ce4..5f8ffb8acb 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 53; // Last changed in PR 3759 +static const u32 STATE_VERSION = 54; // Last changed in PR 3782 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list,