diff --git a/src/core/netplay.cpp b/src/core/netplay.cpp index 8183ac3d9..da3edb3e3 100644 --- a/src/core/netplay.cpp +++ b/src/core/netplay.cpp @@ -44,7 +44,6 @@ static void SetSettings(); // l = local, r = remote static s32 Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ldelay, u32 pred); -static void Close(); static void AdvanceFrame(u16 checksum = 0); static void RunFrame(); @@ -139,8 +138,10 @@ s32 Netplay::Start(s32 lhandle, u16 lport, std::string& raddr, u16 rport, s32 ld return result; } -void Netplay::Close() +void Netplay::CloseSession() { + Assert(IsActive()); + ggpo_close_session(s_ggpo); s_ggpo = nullptr; s_save_buffer_pool.clear(); @@ -210,7 +211,7 @@ void Netplay::HandleTimeSyncEvent(float frame_delta, int update_interval) float iterations_per_frame = 1.0f / s_frame_period; s_target_speed = (s_frame_period + added_time_per_frame) * iterations_per_frame; - s_next_timesync_recovery_frame = CurrentFrame() + std::ceil(static_cast(update_interval) * 0.8f); + s_next_timesync_recovery_frame = CurrentFrame() + static_cast(std::ceil(static_cast(update_interval) * 0.8f)); UpdateThrottlePeriod(); @@ -381,7 +382,8 @@ void Netplay::StopNetplaySession() if (!IsActive()) return; - Close(); + // This will call back to us. + System::ShutdownSystem(false); } void Netplay::NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags) @@ -393,13 +395,13 @@ void Netplay::NetplayAdvanceFrame(Netplay::Input inputs[], int disconnect_flags) void Netplay::ExecuteNetplay() { - while (System::IsValid()) + while (System::IsRunning()) { Netplay::RunFrame(); // this can shut us down Host::PumpMessagesOnCPUThread(); - if (!System::IsValid() || !Netplay::IsActive()) + if (!System::IsValid()) break; System::PresentFrame(); diff --git a/src/core/netplay.h b/src/core/netplay.h index d73efbaf3..5b871a204 100644 --- a/src/core/netplay.h +++ b/src/core/netplay.h @@ -19,6 +19,10 @@ void StopNetplaySession(); bool IsActive(); +/// Frees up resources associated with the current netplay session. +/// Should only be called by System::ShutdownSystem(). +void CloseSession(); + /// Runs the VM and netplay loop. when the netplay loop cancels it switches to normal execute mode. void ExecuteNetplay(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 9c339f5e4..32fb651b6 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1532,7 +1532,7 @@ void System::Execute() // this can shut us down Host::PumpMessagesOnCPUThread(); - if (!IsValid() || Netplay::IsActive()) + if (!IsValid()) return; if (s_frame_step_request) @@ -3741,6 +3741,9 @@ void System::ShutdownSystem(bool save_resume_state) if (!IsValid()) return; + if (Netplay::IsActive()) + Netplay::CloseSession(); + if (save_resume_state) SaveResumeState();