minetest / minetest_game

Minetest Game - A lightweight and well-maintained base for modding [https://github.com/minetest/minetest/]
http://minetest.net/
Other
1.42k stars 571 forks source link

Bug: mod bones - server crash when use 'minetest.punch_node()' from any mod #3145

Closed berengma closed 2 weeks ago

berengma commented 1 month ago

Version:

Minetest 5.8.0 (Linux)
Using LuaJIT 2.1.0-beta3
BUILD_TYPE=Release
RUN_IN_PLACE=0
USE_CURL=1
STATIC_SHAREDIR="/usr/local/share/minetest"

Error message from log:

2024-07-27 01:58:25: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'bones' in callback luaentity_Step(): "Runtime error from mod 'bones' in callback node_on_punch(): ...l/share/minetest/games/minetest_game/mods/bones/init.lua:100: attempt to index local 'player_inv' (a ni
2024-07-27 01:58:25: ERROR[Main]: l value)
2024-07-27 01:58:25: ERROR[Main]: stack traceback:
2024-07-27 01:58:25: ERROR[Main]:       ...l/share/minetest/games/minetest_game/mods/bones/init.lua:100: in function <...l/share/minetest/games/minetest_game/mods/bones/init.lua:85>
2024-07-27 01:58:25: ERROR[Main]:       [C]: in function 'punch_node'

reproduction:

possible solution:

SmallJoker commented 1 month ago

Reproduced by spawning new bones (do not place manually).

minetest.register_chatcommand("p", {
    func = function(name, param)
        local pos = minetest.get_player_by_name(name):get_pos()

        local node_name = #param > 0 and param or "bones:bones"
        local np = minetest.find_node_near(pos, 4, node_name, true)
        if not np then
            return false, "No node found"
        end
        minetest.punch_node(np)
        return true, "OK!"
    end
})

Even though the Lua API states that puncher may be nil, but the C++ side creates an empty ObjectRef, which in turn does not have an inventory.

What is the expected result? Would you like to remove the node and destroy all of its contents, drop the contents as item entities, or disallow any interaction?

berengma commented 1 month ago

Difficult to say what the expected result is. Depends on the mod which uses the method. Disallowing any interaction is probably not what I wanted to have, when I wrote a bone harvester mod. Removing the node and destroy everything is something the involving mod could handle by itself. I think dropping the contents and removing the bones node would be the best option. Thinking in terms of what other mods could do with the results.

berengma commented 1 month ago

see PR #3146