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/PerformanceMetrics.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Source/Core/VideoCommon/PerformanceMetrics.cpp') diff --git a/Source/Core/VideoCommon/PerformanceMetrics.cpp b/Source/Core/VideoCommon/PerformanceMetrics.cpp index 8d18b846ef..520f9d8b95 100644 --- a/Source/Core/VideoCommon/PerformanceMetrics.cpp +++ b/Source/Core/VideoCommon/PerformanceMetrics.cpp @@ -35,6 +35,12 @@ void PerformanceMetrics::CountVBlank() m_vps_counter.Count(); } +void PerformanceMetrics::OnEmulationStateChanged([[maybe_unused]] Core::State state) +{ + m_fps_counter.InvalidateLastTime(); + m_vps_counter.InvalidateLastTime(); +} + void PerformanceMetrics::CountThrottleSleep(DT sleep) { m_time_sleeping += sleep; -- cgit v1.2.3