summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorStenzek <stenzek@gmail.com>2019-06-30 00:06:59 +1000
committerStenzek <stenzek@gmail.com>2019-07-24 05:19:22 +1000
commit560074cf9fed14ff263e3ba7c815af9e4ec1ad4e (patch)
tree0b23f442fc956e96b1987a77519f59c62bcd97e3 /Source/Core
parent137009affef20bfaa91ff32ea1bb6693c09e03c2 (diff)
Core: Fix crash when state is loaded while waiting for the CPU
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/State.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp
index 4e47306152..1350fa9b09 100644
--- a/Source/Core/Core/State.cpp
+++ b/Source/Core/Core/State.cpp
@@ -63,7 +63,7 @@ static AfterLoadCallbackFunc s_on_after_load_callback;
// Temporary undo state buffer
static std::vector<u8> g_undo_load_buffer;
static std::vector<u8> g_current_buffer;
-static int g_loadDepth = 0;
+static bool s_load_or_save_in_progress;
static std::mutex g_cs_undo_load_buffer;
static std::mutex g_cs_current_buffer;
@@ -385,6 +385,11 @@ static void CompressAndDumpState(CompressAndDumpState_args save_args)
void SaveAs(const std::string& filename, bool wait)
{
+ if (s_load_or_save_in_progress)
+ return;
+
+ s_load_or_save_in_progress = true;
+
Core::RunOnCPUThread(
[&] {
// Measure the size of the buffer.
@@ -423,6 +428,8 @@ void SaveAs(const std::string& filename, bool wait)
}
},
true);
+
+ s_load_or_save_in_progress = false;
}
bool ReadHeader(const std::string& filename, StateHeader& header)
@@ -521,7 +528,7 @@ static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_
void LoadAs(const std::string& filename)
{
- if (!Core::IsRunning())
+ if (!Core::IsRunning() || s_load_or_save_in_progress)
{
return;
}
@@ -531,10 +538,10 @@ void LoadAs(const std::string& filename)
return;
}
+ s_load_or_save_in_progress = true;
+
Core::RunOnCPUThread(
[&] {
- g_loadDepth++;
-
// Save temp buffer for undo load state
if (!Movie::IsJustStartingRecordingInputFromSaveState())
{
@@ -580,17 +587,16 @@ void LoadAs(const std::string& filename)
Core::DisplayMessage("The savestate could not be loaded", OSD::Duration::NORMAL);
// since we could be in an inconsistent state now (and might crash or whatever), undo.
- if (g_loadDepth < 2)
- UndoLoadState();
+ UndoLoadState();
}
}
if (s_on_after_load_callback)
s_on_after_load_callback();
-
- g_loadDepth--;
},
true);
+
+ s_load_or_save_in_progress = false;
}
void SetOnAfterLoadCallback(AfterLoadCallbackFunc callback)