diff options
author | Vaxry <[email protected]> | 2024-05-07 13:30:31 +0100 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-05-07 13:30:41 +0100 |
commit | 2bcc8d303f889432171c5113af5f2962858099a4 (patch) | |
tree | ce0e567a9780b60ce3a6f276fc37e76e5cb847b8 | |
parent | 375e77e398b3d69ca90ed58420b929523576c6ef (diff) | |
download | Hyprland-2bcc8d303f889432171c5113af5f2962858099a4.tar.gz Hyprland-2bcc8d303f889432171c5113af5f2962858099a4.zip |
eventloop: don't call lost timers
-rw-r--r-- | src/managers/eventLoop/EventLoopManager.cpp | 4 | ||||
-rw-r--r-- | src/managers/eventLoop/EventLoopManager.hpp | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/managers/eventLoop/EventLoopManager.cpp b/src/managers/eventLoop/EventLoopManager.cpp index c78bc551..5910e71a 100644 --- a/src/managers/eventLoop/EventLoopManager.cpp +++ b/src/managers/eventLoop/EventLoopManager.cpp @@ -31,7 +31,7 @@ void CEventLoopManager::enterLoop(wl_display* display, wl_event_loop* wlEventLoo void CEventLoopManager::onTimerFire() { for (auto& t : m_sTimers.timers) { - if (t->passed() && !t->cancelled()) + if (t.strongRef() > 1 /* if it's 1, it was lost. Don't call it. */ && t->passed() && !t->cancelled()) t->call(t); } @@ -62,6 +62,8 @@ static void timespecAddNs(timespec* pTimespec, int64_t delta) { } void CEventLoopManager::nudgeTimers() { + // remove timers that have gone missing + std::erase_if(m_sTimers.timers, [](const auto& t) { return t.strongRef() <= 1; }); long nextTimerUs = 10 * 1000 * 1000; // 10s diff --git a/src/managers/eventLoop/EventLoopManager.hpp b/src/managers/eventLoop/EventLoopManager.hpp index 13d74571..f2ba61a4 100644 --- a/src/managers/eventLoop/EventLoopManager.hpp +++ b/src/managers/eventLoop/EventLoopManager.hpp @@ -12,6 +12,8 @@ class CEventLoopManager { CEventLoopManager(); void enterLoop(wl_display* display, wl_event_loop* wlEventLoop); + + // Note: will remove the timer if the ptr is lost. void addTimer(SP<CEventLoopTimer> timer); void removeTimer(SP<CEventLoopTimer> timer); |