Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors returned with luajit but not lua 5.4 #3908

Closed
vredesbyyrd opened this issue Apr 1, 2024 · 2 comments
Closed

Errors returned with luajit but not lua 5.4 #3908

vredesbyyrd opened this issue Apr 1, 2024 · 2 comments

Comments

@vredesbyyrd
Copy link

vredesbyyrd commented Apr 1, 2024

Output of awesome --version:

awesome v4.3-1647-ge6f5c7980-dirty (Too long)
• Compiled against Lua 5.1.4 (running with LuaJIT 2.1.1702233742)
• API level: 4
• D-Bus support: yes
• xcb-errors support: yes
• execinfo support: yes
• xcb-randr version: 1.6
• LGI version: 0.9.2
• Transparency enabled: yes
• Custom search paths: no

How to reproduce the issue:

I wrapped my panel (wibox) code in a function to allow for re-initializing the wibar for day/night theme changes without having to call awesome-restart(). Main reason being it's smoother. I know this may not be how awesome was designed to work, but when using lua 5.4 everything works fine and without errors. When using luajit, everything appears to work fine, but awesome returns some errors to stderr. I do not expect answers on this one, but figured I should report in case it's a bug on the awesome side. Although, if anyone has any ideas I would love to hear them.

For some context, here is some pseudo code of the function:

function buildPanel(s)
    local widget 1
    local widget 2
    etc...

    if s.index == 1 then -- bar for screen 1
        if s.bar then s.bar.visible == false end  --  if bar already exists, remove it
        s.bar = wibox{}
        s.bar:struts{}
        s.bar:setup{}
        s.bar.visible = true
    end
    if s.index == 2 then -- bar for screen 2
        if s.bar then s.bar.visible == false end --  if bar already exists, remove it
        s.bar = wibox{}
        s.bar:struts{}
        s.bar:setup{}
        s.bar.visible = true
    end
end

screen.connect_signal("request::desktop_decoration", function(s)
    -- setup tags per screen
    if s.index==1 then
        awful.tag.add("main", {
            layout = awful.layout.suit.floating,
            ...
        })
        awful.tag.add("foto", {
            layout = awful.layout.suit.floating,
            ...
        })
        awful.tag.add("code", {
            layout = awful.layout.suit.tile.left,
            ...
        })
    elseif s.index==2 then
        awful.tag({ "main", "foto"}, screen[2], awful.layout.suit.floating)
    end
    
    buildPanel(s)  -- build the panel/bar
end)

And for theme changes, this is run:

if [[ "$*" == *day* ]]; then
    awesome-client "beautiful=require('beautiful');
                   beautiful.init('/home/clu/.config/awesome/theme_light.lua');
                   for i=1,screen.count() do buildPanel(screen[i]) end"
elif [[ "$*" == *night* ]]; then
    awesome-client "beautiful=require('beautiful');
                   beautiful.init('/home/clu/.config/awesome/theme_dark.lua')
                   for i=1,screen.count() do buildPanel(screen[i]) end"
fi

Actual result:

It does not happen immediately, but usually within a minute of running the above shell script awesome prints this error, and continues to occasionally print the error:

2024-03-31 18:30:22 E: awesome: Error during a protected call: /usr/share/awesome/lib/wibox/widget/textbox.lua:178: attempt to index field 'layout' (a userdata value)
stack traceback:
	/usr/share/awesome/lib/wibox/widget/textbox.lua:178: in function 'set_markup_silently'
	/usr/share/awesome/lib/wibox/widget/textbox.lua:226: in function 'set_markup'
	/usr/share/awesome/lib/wibox/widget/textclock.lua:193: in function </usr/share/awesome/lib/wibox/widget/textclock.lua:186>
	[C]: in function 'xpcall'
	/usr/share/awesome/lib/gears/protected_call.lua:41: in function 'protected_call'
	/usr/share/awesome/lib/gears/timer.lua:237: in function 'func'
	/usr/share/awesome/lib/gears/object.lua:164: in function </usr/share/awesome/lib/gears/object.lua:161>
	[C]: in function 'xpcall'
	/usr/share/awesome/lib/gears/protected_call.lua:41: in function 'protected_call'
	/usr/share/awesome/lib/gears/timer.lua:103: in function </usr/share/awesome/lib/gears/timer.lua:102>

Expected result:

Ideally, no errors returned. I am not programmer, my best guess is there are some references hanging around, and differences between lua 5.4 and luajit garbage collectors may be involved. I tried running collectgarbage("collect") right after if s.bar then s.bar.visible == false end but it made no difference.

I can run lua 5.4 and just forget about it, but luajit does seem to perform a bit better when using more than 1 display, although that could be in my head :) If anyone has any thoughts it would be appreciated.

Thanks for your time!

@vredesbyyrd
Copy link
Author

Just a note, probably unrelated to this issue - After reading into the doc further I probably should be using awful.widget.only_on_screen for the wibox's, rather than if screen.index == foo.

@vredesbyyrd
Copy link
Author

vredesbyyrd commented Apr 2, 2024

So after testing the below code over the last few hours, I have not been able to reproduce the errors.

local function run_delayed_calls()
    require("gears.timer").run_delayed_calls_now()
end

if s.mywibox then
    s.mywibox.visible = false
    s.mywibox = nil
end
run_delayed_calls()
for _=1, 3 do
    collectgarbage("collect")
end

I'm not sure if there are any negatives to calling run_delayed_calls() in this context.

I also noticed the same errors when disconnecting my external monitor. Running the same code prevents the errors.

screen.connect_signal("removed", function(s)
    s.mywibox.visible = false
    s.mywibox = nil
    run_delayed_calls()
    for _=1, 3 do
        collectgarbage("collect")
    end
end)

As a non-programmer, my understanding (a best guess) is that run_delayed_calls() runs all delayed calls now, making sure signals are not sent to references that no longer exist. Regarding the gc, I assume it just cannot keep up.

I'll close this now since I can no longer reproduce the issue. Maybe i'll reopen if they pop up again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant