minetest-mods / i3

:rocket: A next-generation inventory for Minetest 5.6+
Other
41 stars 26 forks source link

Infinite recusion #54

Closed mrbid closed 2 years ago

mrbid commented 2 years ago

common.lua > core.is_creative_enabled

kilbith commented 2 years ago

Ok? What am I supposed to guess? Give me details please.

mrbid commented 2 years ago
local old_is_creative_enabled = core.is_creative_enabled

function core.is_creative_enabled(name)
    if name == "" then
        return old_is_creative_enabled(name)
    end

    return core.check_player_privs(name, {creative = true}) or old_is_creative_enabled(name)
end

old_is_creative_enabled just calls core.is_creative_enabled again, it's redundant. I recommend.

function core.is_creative_enabled(name)
    if name ~= nil and name == "" then
        return false
    end
    return core.check_player_privs(name, {creative = true})
end

I noticed this part of the code crashing my server quite a few times and the stack trace leading through 3d_armor and skinsdb.

2022-02-18 08:30:43: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'i3' in callback environment_Step(): (load):19: core.check_player_privs expects a player or playername as argument.
2022-02-18 08:30:43: ERROR[Main]: stack traceback:
2022-02-18 08:30:43: ERROR[Main]:   [C]: in function 'error'
2022-02-18 08:30:43: ERROR[Main]:   ...home/x/mtnew/minetest/bin/../builtin/game/misc.lua:23: in function 'check_player_privs'
2022-02-18 08:30:43: ERROR[Main]:   (load):19: in function 'is_creative_enabled'
2022-02-18 08:30:43: ERROR[Main]:   (load):1255: in function 'hide_items'
2022-02-18 08:30:43: ERROR[Main]:   (load):1272: in function 'get_items_fs'
2022-02-18 08:30:43: ERROR[Main]:   (load):1493: in function 'make_fs'
2022-02-18 08:30:43: ERROR[Main]:   (load):170: in function 'func'
2022-02-18 08:30:43: ERROR[Main]:   ...e/x/mtnew/minetest/bin/../builtin/common/after.lua:20: in function '?'
2022-02-18 08:30:43: ERROR[Main]:   .../x/mtnew/minetest/bin/../builtin/game/register.lua:425: in function <.../x/mtnew/minetest/bin/../builtin/game/register.lua:409>

But after nil checking that part of the code and another part of the code, I forget which now, it seems to have stopped this.

SmallJoker commented 2 years ago

Is there any further backtrace before register.lua? I suppose there's a mod (or i3 itself) that calls to core.is_creative_enabled using invalid parameters (nil?). Also this is not recursion.

mrbid commented 2 years ago

sadly that is all the output I have

kilbith commented 2 years ago

MTG's creative shares the same code and there has been no issue with it so far.