summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/PerformanceMetrics.cpp
diff options
context:
space:
mode:
authorDentomologist <dentomologist@gmail.com>2026-03-07 12:33:39 -0800
committerDentomologist <dentomologist@gmail.com>2026-03-07 12:50:59 -0800
commit252ec7452c4c908537036215c1888f5c5d596bd7 (patch)
tree3a4dda9454f04b8d10af7669b165c4ec149f9511 /Source/Core/VideoCommon/PerformanceMetrics.cpp
parent49d5299f1e41930d31cc83dc28c4c583589ff674 (diff)
PerformanceMetrics: Use HookableEvent for state changed callback
Use the normal state changed `HookableEvent` instead of having `Core::NotifyStateChanged` call `g_perf_metrics.OnEmulationStateChanged` directly. The direct call was added in bad78cfed416d89ceb6b0acf6c134d3691b3d624 to avoid a crash. At the time state changed callbacks were stored in a vector, and the crash was caused by `g_perf_metric`'s destructor trying to remove the callback from the already-destroyed vector. Later a97627e736ff352e031123519c799e65cc98b32c switched state changed callbacks to use `HookableEvent`, which is specifically designed to handle the case where a hook outlives its associated event. Since the workaround is no longer necessary replace it with a standard `EventHook`.
Diffstat (limited to 'Source/Core/VideoCommon/PerformanceMetrics.cpp')
-rw-r--r--Source/Core/VideoCommon/PerformanceMetrics.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/Source/Core/VideoCommon/PerformanceMetrics.cpp b/Source/Core/VideoCommon/PerformanceMetrics.cpp
index 0e2e371d4e..cba4beb8c6 100644
--- a/Source/Core/VideoCommon/PerformanceMetrics.cpp
+++ b/Source/Core/VideoCommon/PerformanceMetrics.cpp
@@ -8,11 +8,22 @@
#include <imgui.h>
#include <implot.h>
+#include "Common/HookableEvent.h"
#include "Core/Config/GraphicsSettings.h"
+#include "Core/Core.h"
#include "VideoCommon/VideoConfig.h"
PerformanceMetrics g_perf_metrics;
+PerformanceMetrics::PerformanceMetrics()
+{
+ const auto invalidate_counters_last_time = [this](Core::State) {
+ m_fps_counter.InvalidateLastTime();
+ m_vps_counter.InvalidateLastTime();
+ };
+ m_state_change_hook = Core::AddOnStateChangedCallback(invalidate_counters_last_time);
+}
+
void PerformanceMetrics::Reset()
{
m_fps_counter.Reset();
@@ -37,12 +48,6 @@ 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;