From f82d08e22356955e02aaa035dbf2842e49f9b8d4 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 15 Oct 2023 21:41:00 +1000 Subject: [PATCH] TimingEvents: Reset downcount when head is resorted --- src/core/timing_event.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/timing_event.cpp b/src/core/timing_event.cpp index 80204cf67..845708e2c 100644 --- a/src/core/timing_event.cpp +++ b/src/core/timing_event.cpp @@ -52,7 +52,8 @@ std::unique_ptr CreateTimingEvent(std::string name, TickCount perio void UpdateCPUDowncount() { - CPU::g_state.downcount = CPU::HasPendingInterrupt() ? 0 : s_active_events_head->GetDowncount(); + const u32 event_downcount = s_active_events_head->GetDowncount(); + CPU::g_state.downcount = CPU::HasPendingInterrupt() ? 0 : event_downcount; } TimingEvent** GetHeadEventPtr() @@ -113,9 +114,14 @@ static void SortEvent(TimingEvent* event) // unlink if (event->prev) + { event->prev->next = event->next; + } else + { s_active_events_head = event->next; + UpdateCPUDowncount(); + } if (event->next) event->next->prev = event->prev; else @@ -128,9 +134,14 @@ static void SortEvent(TimingEvent* event) event->prev = current->prev; if (current->prev) + { current->prev->next = event; + } else + { s_active_events_head = event; + UpdateCPUDowncount(); + } current->prev = event; }