EmperorPenguin18 / mpv-jellyfin

mpv plugin that turns it into a Jellyfin client
The Unlicense
29 stars 3 forks source link

attempt to perform arithmetic on a nil value #5

Open gasune opened 5 months ago

gasune commented 5 months ago

Not exactly sure why i got the error after pressing right arrow key until i reached the 'episodes' part of jellyfin. from the console, the problematic part seems to be here:

local function update_list()
    overlay.data = ""
    local magic_num = 29 -- const
    list_start[layer] = list_start[layer] or 1  -- this one line fixed my "attempt to perform arithmetic on a nil value" error
    if selection[layer] - list_start[layer] > magic_num then  -- errored here
        list_start[layer] = selection[layer] - magic_num
    elseif selection[layer] - list_start[layer] < 0 then
        list_start[layer] = selection[layer]
    end
    for i=list_start[layer],list_start[layer]+magic_num do
        if i > #items then break end
        local index = ""
        if items[i].IndexNumber and items[i].IsFolder == false then
            index = items[i].IndexNumber..". "
        else
            -- nothing
        end
        if i == selection[layer] then
            overlay.data = overlay.data.."{\\fs16}{\\c&HFF&}"..index..items[i].Name.."\n"
        else
            overlay.data = overlay.data.."{\\fs16}"..index..items[i].Name.."\n"
        end
    end
    overlay:update()
end

EDIT: Seems like the amount of folders and lack of arrays in list_layer caused it to give the error.

For example: Folder1 -> Folder2 -> Folder3 wouldn't produce the error as there are indeed 3 arrays.

Folder1 -> Folder2 -> Folder3 -> Folder4 would give a nil error since there are only 3 arrays, yet 4 layers(?)

So, by adding arrays as needed seems to have fixed it:

if #list_start < layer then table.insert(list_start, 1) end
EmperorPenguin18 commented 4 months ago

Yes thank you for reporting this, you identified the issue exactly. I'll push a fix.