1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-03 05:31:34 +00:00
mpv/player/lua
Avi Halachmi (:avih) 37927b65f7 stats.lua: graphs: fix bad rendering due to division by 0
This fixes two potential divisions by 0 at generate_graph(...):
- If v_avg is (given and) 0.
- if v_max is 0.

The former doesn't seem to happen in practice because v_avg is only
used at one generate_gpah call, where it's apparently not 0.

The latter triggers if all the graph values are 0 (hence v_max is
also 0).

The implication of these divisions by 0 is an invalid y-value which
ends up at the ASS coordinates string for the graph inner content.

On linux the value ends as "nan" (luajit) or "-nan" (lua 5.1/5.2), and
on Windows it's "nan" (luajit) or "-1.#IND00" (lua 5.1/5.2), maybe due
to msvcrt's snprintf.

All these strings are wrong as ASS numbers, but due to luck in how
libass parses the coordinates, "nan" and "-nan" result in empty graph
(which looks OK for "all values are 0"), while "-1.#IND00" is parsed
as -1, which breaks the graph rendering (affects other graphs too).

One example of "all values are 0" is at page 0 (internal performance
graphs) on Windows - because the cpu metrics don't work.
So this fixes at least page 0 on Windows with lua 5.1/5.2.

While at it, move the scale calculations to one place, which now
avoids division by 0, instead of duplicating this calculation.

In the future, we can consider improving the generate_graph API:
- It needs one peak value, but takes 3 (v_max, v_avg, scale) which
  are meshed into one final value.
- v_avg is only used in 1 of 6 call sites, but at the middle of the
  arguments, so all other call sites need to pass explicit "nil".
- "scale" is arbitrary and used to leave some space at the top of the
  graph. 5 places use 0.8, one uses 0.9. Could probably be unified.
2022-02-21 16:05:02 +02:00
..
assdraw.lua
auto_profiles.lua auto_profiles.lua: don't warn if profile-restore=default 2022-01-30 15:13:10 +02:00
console.lua console.lua: define remaining emacs keybindings 2021-11-01 23:42:16 +11:00
defaults.lua lua: remove mp.suspend, resume and resume_all 2021-12-15 12:29:10 +01:00
options.lua lua: read_options: quote values at error messages 2021-08-10 11:00:18 +03:00
osc.lua osc.lua: seekbar hover: speed-up chapter access 2022-02-06 11:02:39 +02:00
stats.lua stats.lua: graphs: fix bad rendering due to division by 0 2022-02-21 16:05:02 +02:00
ytdl_hook.lua ytdl_hook.lua: improve check for sub language before inserting all-subs 2021-11-15 15:08:22 +01:00