From bad78cfed416d89ceb6b0acf6c134d3691b3d624 Mon Sep 17 00:00:00 2001 From: Mihai Brodschi Date: Sun, 27 Apr 2025 17:33:23 +0300 Subject: Core, VideoCommon: Fix crash at shutdown due to destructor ordering Previously, PerformanceTracker registered a callback to be updated on emulation state changes. PerformanceTrackers live in a global variable (g_perf_metrics) within libvideocommon. The callback was stored in a global variable in libcore. This created a race condition at shutdown between these libraries, when the PerfTracker's destructor tried to unregister the callback. Notify the PerfTracker directly from libcore, without callbacks, since Core.cpp already references g_perf_metrics explicitly. Also rename Core::CallOnStateChangedCallbacks to NotifyStateChanged to better reflect what it's doing. --- Source/Core/VideoCommon/PerformanceTracker.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Source/Core/VideoCommon/PerformanceTracker.cpp') diff --git a/Source/Core/VideoCommon/PerformanceTracker.cpp b/Source/Core/VideoCommon/PerformanceTracker.cpp index f61f8fe63e..7113f388d1 100644 --- a/Source/Core/VideoCommon/PerformanceTracker.cpp +++ b/Source/Core/VideoCommon/PerformanceTracker.cpp @@ -23,17 +23,9 @@ PerformanceTracker::PerformanceTracker(const std::optional log_name const std::optional
sample_window_duration) : m_log_name{log_name}, m_sample_window_duration{sample_window_duration} { - m_on_state_changed_handle = - Core::AddOnStateChangedCallback([this](Core::State state) { m_is_last_time_sane = false; }); - Reset(); } -PerformanceTracker::~PerformanceTracker() -{ - Core::RemoveOnStateChangedCallback(&m_on_state_changed_handle); -} - void PerformanceTracker::Reset() { m_raw_dts.Clear(); @@ -135,6 +127,11 @@ DT PerformanceTracker::GetLastRawDt() const return m_last_raw_dt; } +void PerformanceTracker::InvalidateLastTime() +{ + m_is_last_time_sane = false; +} + void PerformanceTracker::ImPlotPlotLines(const char* label) const { // "quality" graph uses twice as many points. -- cgit v1.2.3