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.
Showing the changes to player/lua/defaults.lua (1 of 1 file). Show all
Unified · Split
| @@ -528,9 +528,18 @@ function mp.dispatch_events(allow_wait) · 527 unmodified lines | ||
| 528 | 528 | if not more_events then |
| 529 | 529 | wait = process_timers() or 1e20 -- infinity for all practical purposes |
| 530 | 530 | if wait ~= 0 then |
| 531 | + local idle_called = nil | |
| 531 | 532 | for _, handler in ipairs(idle_handlers) do |
| 533 | + idle_called = true | |
| 532 | 534 | handler() |
| 533 | 535 | end |
| 536 | + if idle_called then | |
| 537 | + -- handlers don't complete in 0 time, and may modify timers | |
| 538 | + wait = mp.get_next_timeout() or 1e20 | |
| 539 | + if wait < 0 then | |
| 540 | + wait = 0 | |
| 541 | + end | |
| 542 | + end | |
| 534 | 543 | end |
| 535 | 544 | -- Resume playloop - important especially if an error happened while |
| 536 | 545 | -- suspended, and the error was handled, but no resume was done. |