diff --git a/rpcs3/Emu/Cell/Modules/cellKb.cpp b/rpcs3/Emu/Cell/Modules/cellKb.cpp index f6ae9433d2..131cff6613 100644 --- a/rpcs3/Emu/Cell/Modules/cellKb.cpp +++ b/rpcs3/Emu/Cell/Modules/cellKb.cpp @@ -46,7 +46,7 @@ KeyboardHandlerBase::KeyboardHandlerBase(utils::serial* ar) if (m_info.max_connect) { - Emu.DeferDeserialization([this]() + Emu.PostponeInitCode([this]() { Init(m_info.max_connect); auto lk = init.init(); diff --git a/rpcs3/Emu/Cell/Modules/cellMouse.cpp b/rpcs3/Emu/Cell/Modules/cellMouse.cpp index f7ae70bfb4..4f664eeb3e 100644 --- a/rpcs3/Emu/Cell/Modules/cellMouse.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMouse.cpp @@ -46,7 +46,7 @@ MouseHandlerBase::MouseHandlerBase(utils::serial* ar) if (m_info.max_connect) { - Emu.DeferDeserialization([this]() + Emu.PostponeInitCode([this]() { Init(m_info.max_connect); auto lk = init.init(); diff --git a/rpcs3/Emu/Cell/lv2/sys_cond.cpp b/rpcs3/Emu/Cell/lv2/sys_cond.cpp index 7f284f20de..ba36ad5d14 100644 --- a/rpcs3/Emu/Cell/lv2/sys_cond.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_cond.cpp @@ -45,7 +45,7 @@ CellError lv2_cond::on_id_create() ensure(!!Emu.DeserialManager()); - Emu.DeferDeserialization([this]() + Emu.PostponeInitCode([this]() { if (!mutex) { diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 56bfee417d..26d9ffd590 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -77,7 +77,7 @@ std::shared_ptr lv2_event_queue::load_ptr(utils::serial& ar, st fmt::throw_exception("Failed in event queue pointer deserialization (invalid ID): location: %s, id=0x%x", msg, id); } - Emu.DeferDeserialization([id, &queue, msg_str = std::string{msg}]() + Emu.PostponeInitCode([id, &queue, msg_str = std::string{msg}]() { // Defer resolving queue = idm::get_unlocked(id); diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index c2e4ebcd9a..63d8963ab2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -28,7 +28,7 @@ lv2_int_tag::lv2_int_tag(utils::serial& ar) noexcept if (!ptr && id) { - Emu.DeferDeserialization([id, &handler = this->handler]() + Emu.PostponeInitCode([id, &handler = this->handler]() { handler = ensure(idm::get_unlocked(id)); }); diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 4ebabcc245..ec0d3cd7e2 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -105,7 +105,7 @@ u64 lv2_timer::check_unlocked(u64 _now) noexcept lv2_timer_thread::lv2_timer_thread() { - Emu.DeferDeserialization([this]() + Emu.PostponeInitCode([this]() { idm::select([&](u32 id, lv2_timer&) { diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 77675b7f45..14208d45f6 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -202,22 +202,36 @@ void init_fxo_for_exec(utils::serial* ar, bool full = false) Emu.ConfigurePPUCache(); - g_fxo->init(false, ar); + g_fxo->init(false, ar, [](){ Emu.ExecPostponedInitCode(); }); Emu.GetCallbacks().init_gs_render(ar); Emu.GetCallbacks().init_pad_handler(Emu.GetTitleID()); Emu.GetCallbacks().init_kb_handler(); Emu.GetCallbacks().init_mouse_handler(); + usz pos = 0; + if (ar) { - Emu.ExecDeserializationRemnants(); + pos = ar->pos; + } - [[maybe_unused]] auto flags = (*ar)(Emu.m_savestate_extension_flags1); + // TODO: Remove second call when possible + Emu.ExecPostponedInitCode(); + + if (ar) + { + ensure(pos == ar->pos); + + (*ar)(Emu.m_savestate_extension_flags1); const usz advance = (Emu.m_savestate_extension_flags1 & Emulator::SaveStateExtentionFlags1::SupportsMenuOpenResume ? 32 : 31); - load_and_check_reserved(*ar, advance); // Reserved area + // Reserved area + if (!load_and_check_reserved(*ar, advance)) + { + sys_log.error("Potential failure to load savestate: padding buyes are not 0. %s", *ar); + } } } diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index cff9c88902..4aa7e281ba 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -145,11 +145,11 @@ class Emulator final std::vector>> m_pause_msgs_refs; - std::vector> deferred_deserialization; + std::vector> m_postponed_init_code; - void ExecDeserializationRemnants() + void ExecPostponedInitCode() { - for (auto&& func : ::as_rvalue(std::move(deferred_deserialization))) + for (auto&& func : ::as_rvalue(std::move(m_postponed_init_code))) { func(); } @@ -200,9 +200,9 @@ public: CallFromMainThread(std::move(func), nullptr, true, static_cast(counter)); } - void DeferDeserialization(std::function&& func) + void PostponeInitCode(std::function&& func) { - deferred_deserialization.emplace_back(std::move(func)); + m_postponed_init_code.emplace_back(std::move(func)); } /** Set emulator mode to running unconditionnaly. diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index bdbdce657a..1e4e23e0e7 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -242,7 +242,7 @@ namespace stx *m_info++ = nullptr; } - void init(bool reset = true, utils::serial* ar = nullptr) + void init(bool reset = true, utils::serial* ar = nullptr, std::function func = {}) { if (reset) { @@ -297,6 +297,11 @@ namespace stx } } + if (func) + { + func(); + } + // Launch threads for (auto it = m_info; it != info_before; it--) {