minetest-mods / unified_inventory

An extensible inventory mod which allows searching crafting and browsing for recipes in the same dialogue.
Other
50 stars 38 forks source link

Mysterious crashes when certain players join - unified_inventory, waypoints #182

Closed redblade7 closed 3 years ago

redblade7 commented 3 years ago

On 7/29/2021, I updated all the mods on my three Minetest servers, including unified_inventory. Since then I have been having bizarre occasional server crashes related to unified_inventory and waypoints when certain players join, usually the same players.

The mods had been last updated on 4/11/2021, so this bug has been introduced sometime after then.

Here is the debug.txt output of an example crash:

2021-08-27 05:47:49: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'unified_inventory' in callback on_joinplayer(): ...games/minetest_game/mods/unified_inventory/waypoints.lua:138: attempt to index a nil value 2021-08-27 05:47:49: ERROR[Main]: stack traceback: 2021-08-27 05:47:49: ERROR[Main]: ...games/minetest_game/mods/unified_inventory/waypoints.lua:138: in function 'get_formspec' 2021-08-27 05:47:49: ERROR[Main]: .../games/minetest_game/mods/unified_inventory/internal.lua:70: in function 'get_formspec' 2021-08-27 05:47:49: ERROR[Main]: .../games/minetest_game/mods/unified_inventory/internal.lua:282: in function 'set_inventory_formspec' 2021-08-27 05:47:49: ERROR[Main]: .../games/minetest_game/mods/unified_inventory/internal.lua:355: in function 'apply_filter' 2021-08-27 05:47:49: ERROR[Main]: ...games/minetest_game/mods/unified_inventory/callbacks.lua:20: in function <...games/minetest_game/mods/unified_inventory/callbacks.lua:12> 2021-08-27 05:47:49: ERROR[Main]: (REMOVED)/bin/../builtin/game/register.lua:422: in function <(REMOVED)/bin/../builtin/game/register.lua:406>

SmallJoker commented 3 years ago

Does this fix your issue?

diff --git a/callbacks.lua b/callbacks.lua
index 1f43e39..317c3c8 100644
--- a/callbacks.lua
+++ b/callbacks.lua
@@ -24,8 +24,7 @@ minetest.register_on_joinplayer(function(player)
    unified_inventory.alternate[player_name] = 1
    unified_inventory.current_item[player_name] = nil
    unified_inventory.current_craft_direction[player_name] = "recipe"
-   unified_inventory.set_inventory_formspec(player,
-   unified_inventory.default)
+   unified_inventory.set_inventory_formspec(player, unified_inventory.default)

    -- Refill slot
    local refill = minetest.create_detached_inventory(player_name.."refill", {
diff --git a/internal.lua b/internal.lua
index f83f96b..76a277d 100644
--- a/internal.lua
+++ b/internal.lua
@@ -375,6 +375,5 @@ function ui.apply_filter(player, filter, search_dir)
    ui.current_index[player_name] = 1
    ui.activefilter[player_name] = filter
    ui.active_search_direction[player_name] = search_dir
-   ui.set_inventory_formspec(player,
-   ui.current_page[player_name])
+   ui.set_inventory_formspec(player, ui.current_page[player_name])
 end
diff --git a/waypoints.lua b/waypoints.lua
index 08fce38..1496cdd 100644
--- a/waypoints.lua
+++ b/waypoints.lua
@@ -330,8 +330,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
    end
 end)

-
-minetest.register_on_joinplayer(function(player)
+-- waypoints_temp must be initialized before the general unified_inventory
+-- joinplayer callback is run for updating the inventory
+table.insert(minetest.registered_on_joinplayers, 1, function(player)
    local player_name = player:get_player_name()
    local waypoints = get_waypoint_data(player)
redblade7 commented 3 years ago

Can you please attach this as a normal patch file?

SmallJoker commented 3 years ago

This is a diff, not a patch. Here's the patch (after commit), renamed to .pdf because GitHub does not allow .patch files.

0001-Fix-waypoint-initialization-order.pdf

EDIT: After all, those changes would be pretty simple to perform in an ssh session (only the changes in waypoints.lua) are relevant.

redblade7 commented 3 years ago

Thank you! I've applied the patch to my servers and will let you know if I get any more crashes.

redblade7 commented 3 years ago

I haven't had any crashes since installing the patch.

SmallJoker commented 3 years ago

b1c85a2