From 5b40db385a7b4239e2e78d67f1098209c8592202 Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Tue, 22 Jun 2021 16:06:36 +0300 Subject: lua: idle observers: ensure timers are up-to-date This fixes two issues, both of which resulted from the timers-wait period not being re-calculated after idle-observers were executed: - If timers were added from an idle observer then they could fire long after they were due (only when/if the next mpv event arrives). - Idle observers don't execute in zero time, and the wait period for the next timer was implicitly extended by the idle observers execution time (because it was calculated before the idle observers). This commit ensures that if idle-observers were executed, then the timers wait period is re-calculated, which solves both issues. --- player/lua/defaults.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 5e56c4fb4e..a1deca28ba 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -528,9 +528,18 @@ function mp.dispatch_events(allow_wait) if not more_events then wait = process_timers() or 1e20 -- infinity for all practical purposes if wait ~= 0 then + local idle_called = nil for _, handler in ipairs(idle_handlers) do + idle_called = true handler() end + if idle_called then + -- handlers don't complete in 0 time, and may modify timers + wait = mp.get_next_timeout() or 1e20 + if wait < 0 then + wait = 0 + end + end end -- Resume playloop - important especially if an error happened while -- suspended, and the error was handled, but no resume was done. -- cgit v1.2.3