From baa6f0186c7727bb7e0e11e72ebb907d642d3460 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 29 Sep 2019 07:54:45 +0200 Subject: [PATCH] profiler: fix a crash on exit. --- src/profiler.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/profiler.cpp b/src/profiler.cpp index c27d8733..e7d671d0 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -20,24 +20,31 @@ namespace lol * Profiler implementation class */ -static class ProfilerData +static class profiler_data { friend class Profiler; - static int const HISTORY = 32; - -public: - ProfilerData() + void update() { - for (int i = 0; i < HISTORY; i++) - history[i] = 0.0f; + history[frame++ % HISTORY] = m_timer.get(); avg = max = 0.0f; + + for (int i = 0; i < HISTORY; i++) + { + avg += history[i]; + if (history[i] > max) + max = history[i]; + } + avg /= HISTORY; } + static int const HISTORY = 32; + private: - float history[HISTORY]; + float history[HISTORY] = { 0.0f }; + int frame = 0; timer m_timer; - float avg, max; + float avg = 0.0f, max = 0.0f; } data[Profiler::STAT_COUNT]; @@ -52,19 +59,7 @@ void Profiler::Start(int id) void Profiler::Stop(int id) { - float seconds = data[id].m_timer.get(); - - data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds; - data[id].avg = 0.0f; - data[id].max = 0.0f; - - for (int i = 0; i < ProfilerData::HISTORY; i++) - { - data[id].avg += data[id].history[i]; - if (data[id].history[i] > data[id].max) - data[id].max = data[id].history[i]; - } - data[id].avg /= ProfilerData::HISTORY; + data[id].update(); } float Profiler::GetAvg(int id)