From b2e969eb8fb654acb89e5cfeec6c050a440449e4 Mon Sep 17 00:00:00 2001 From: Eladash <18193363+elad335@users.noreply.github.com> Date: Tue, 3 Oct 2023 19:10:52 +0300 Subject: [PATCH] Savestates: Fix rsxaudio --- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_event.cpp | 18 ++++++++++++++---- rpcs3/Emu/Cell/lv2/sys_event.h | 2 +- rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp | 8 ++++---- rpcs3/Emu/Cell/lv2/sys_timer.cpp | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index 1dcbb6ceae..c46b09b8a5 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -419,7 +419,7 @@ cell_audio_thread::cell_audio_thread(utils::serial& ar) for (key_info& k : keys) { ar(k.start_period, k.flags, k.source); - k.port = lv2_event_queue::load_ptr(ar, k.port); + k.port = lv2_event_queue::load_ptr(ar, k.port, "audio"); } ar(ports); diff --git a/rpcs3/Emu/Cell/lv2/sys_event.cpp b/rpcs3/Emu/Cell/lv2/sys_event.cpp index 10d9c7ffbc..9e41d952cb 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_event.cpp @@ -57,7 +57,7 @@ void lv2_event_queue::save_ptr(utils::serial& ar, lv2_event_queue* q) ar(q->id); } -std::shared_ptr lv2_event_queue::load_ptr(utils::serial& ar, std::shared_ptr& queue) +std::shared_ptr lv2_event_queue::load_ptr(utils::serial& ar, std::shared_ptr& queue, std::string_view msg) { const u32 id = ar.operator u32(); @@ -72,10 +72,20 @@ std::shared_ptr lv2_event_queue::load_ptr(utils::serial& ar, st return q; } - Emu.DeferDeserialization([id, &queue]() + if (id >> 24 != id_base >> 24) + { + 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}]() { // Defer resolving - queue = ensure(idm::get_unlocked(id)); + queue = idm::get_unlocked(id); + + if (!queue) + { + fmt::throw_exception("Failed in event queue pointer deserialization (not found): location: %s, id=0x%x", msg_str, id); + } }); // Null until resolved @@ -85,7 +95,7 @@ std::shared_ptr lv2_event_queue::load_ptr(utils::serial& ar, st lv2_event_port::lv2_event_port(utils::serial& ar) : type(ar) , name(ar) - , queue(lv2_event_queue::load_ptr(ar, queue)) + , queue(lv2_event_queue::load_ptr(ar, queue, "eventport")) { } diff --git a/rpcs3/Emu/Cell/lv2/sys_event.h b/rpcs3/Emu/Cell/lv2/sys_event.h index 90fd092f55..bf872cc4ba 100644 --- a/rpcs3/Emu/Cell/lv2/sys_event.h +++ b/rpcs3/Emu/Cell/lv2/sys_event.h @@ -101,7 +101,7 @@ struct lv2_event_queue final : public lv2_obj static std::shared_ptr load(utils::serial& ar); void save(utils::serial& ar); static void save_ptr(utils::serial&, lv2_event_queue*); - static std::shared_ptr load_ptr(utils::serial& ar, std::shared_ptr& queue); + static std::shared_ptr load_ptr(utils::serial& ar, std::shared_ptr& queue, std::string_view msg = {}); CellError send(lv2_event event); diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index 2116da6c88..701d741341 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -111,9 +111,9 @@ lv2_rsxaudio::lv2_rsxaudio(utils::serial& ar) noexcept { ar(shmem); - for (const auto& port : event_queue) + for (auto& port : event_queue) { - lv2_event_queue::save_ptr(ar, port.get()); + port = lv2_event_queue::load_ptr(ar, port, "rsxaudio"); } } } @@ -128,9 +128,9 @@ void lv2_rsxaudio::save(utils::serial& ar) { ar(shmem); - for (auto& port : event_queue) + for (const auto& port : event_queue) { - port = lv2_event_queue::load_ptr(ar, port); + lv2_event_queue::save_ptr(ar, port.get()); } } } diff --git a/rpcs3/Emu/Cell/lv2/sys_timer.cpp b/rpcs3/Emu/Cell/lv2/sys_timer.cpp index 2bae4ea719..29807be4ef 100644 --- a/rpcs3/Emu/Cell/lv2/sys_timer.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_timer.cpp @@ -33,7 +33,7 @@ struct lv2_timer_thread lv2_timer::lv2_timer(utils::serial& ar) : lv2_obj{1} , state(ar) - , port(lv2_event_queue::load_ptr(ar, port)) + , port(lv2_event_queue::load_ptr(ar, port, "timer")) , source(ar) , data1(ar) , data2(ar)