diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 10662f659e..28b54ba1b7 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -3318,6 +3318,14 @@ void Emulator::Kill(bool allow_autoexit, bool savestate, savestate_stage* save_s set_progress_message("Commiting File"); + fs::file to_close_file; + { + auto reset = init_mtx->reset(); + to_close_file = std::move(file.file); + reset.set_init(); + } + to_close_file.close(); + if (!file.commit() || !fs::get_stat(path, file_stat)) { sys_log.error("Failed to write savestate to file! (path='%s', %s)", path, fs::g_tls_error); diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 5a9ae9aaf4..35f7e7e255 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -713,13 +713,26 @@ void gui_application::InitializeCallbacks() std::string verbose_message; usz bytes_written = 0; + while (true) { - auto init = static_cast(init_mtx.get())->access(); + auto mtx = static_cast(init_mtx.get()); + auto init = mtx->access(); if (!init) { - pdlg->reject(); - return; + // Try to wait for the abort process to complete + auto fake_reset = mtx->reset(); + if (!fake_reset) + { + // End of emulation termination + pdlg->reject(); + return; + } + + fake_reset.set_init(); + + // Now ar_ptr contains a null file descriptor + continue; } if (auto str_ptr = code_location->load()) @@ -727,11 +740,12 @@ void gui_application::InitializeCallbacks() verbose_message = "\n" + *str_ptr; } - *half_seconds += 1; - - bytes_written = ar_ptr->get_size(); + bytes_written = std::max(ar_ptr->get_size(), old_written); + break; } + *half_seconds += 1; + if (old_written == bytes_written) { if (repeat_count == 60)