0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00
mpv/player
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
..
javascript js: utils.get_user_path: make wrapper of expand-path 2022-02-04 12:53:16 +02:00
lua stats.lua: graphs: fix bad rendering due to division by 0 2022-02-21 16:05:02 +02:00
audio.c audio: fix typo 2021-12-03 14:04:58 -08:00
client.c player: make deprecated track/chapter/metadata events internal 2021-12-15 12:29:10 +01:00
client.h scripting: remove race condition when toggling internal scripts 2020-03-26 23:59:44 +01:00
command.c vo_gpu_next: refactor subtitle rendering 2022-02-21 12:01:44 +01:00
command.h player: make deprecated track/chapter/metadata events internal 2021-12-15 12:29:10 +01:00
configfiles.c options: add watch-later-options 2021-07-21 13:19:28 +00:00
core.h player: add track-list/N/image sub-property 2021-10-14 15:39:07 +00:00
external_files.c player: add thd (TrueHD) to whitelist of audio extensions 2022-01-19 14:00:05 +00:00
external_files.h player: add automatic loading of external cover art files 2020-09-28 00:12:52 +02:00
javascript.c js: utils.get_user_path: make wrapper of expand-path 2022-02-04 12:53:16 +02:00
loadfile.c player: make deprecated track/chapter/metadata events internal 2021-12-15 12:29:10 +01:00
lua.c lua: remove mp.suspend, resume and resume_all 2021-12-15 12:29:10 +01:00
main.c options: add watch-later-options 2021-07-21 13:19:28 +00:00
misc.c audio: refactor how data is passed to AO 2020-08-29 13:12:32 +02:00
osd.c player: add --term-title option 2020-05-25 20:39:37 +02:00
playloop.c options: add always to stop-screensaver 2022-02-18 22:04:08 +00:00
screenshot.c screenshot: add --screenshot-sw option 2020-10-05 00:16:46 +02:00
screenshot.h player: make screenshot each-frame mode more accurate 2020-02-07 13:32:21 +01:00
scripting.c player/scripting: fix use-after-free when loading script folders 2021-04-08 23:47:35 +03:00
sub.c sub: align ytdl-hook secondary subs to the top 2021-08-11 18:15:35 +00:00
video.c {player,video}: remove references to obsolete opengl-cb API 2021-12-15 12:29:10 +01:00