minetest-mods / xdecor

A decoration mod for Minetest meant to be light, simple and well-featured
Other
29 stars 45 forks source link

Server crash (workbench nil value) #86

Closed aerozoic closed 7 years ago

aerozoic commented 7 years ago

I have no idea what caused this.

2017-09-20 14:24:33: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'xdecor' in callback node_on_receive_fields(): .../.minetest/games/UGXrealms/mods/xdecor/src/workbench.lua:133: attempt to concatenate a nil value
2017-09-20 14:24:33: ERROR[Main]: Stack Traceback
2017-09-20 14:24:33: ERROR[Main]: ===============
2017-09-20 14:24:33: ERROR[Main]: (2) Lua method 'set_formspec' at file '/home/UGX/.minetest/games/UGXrealms/mods/xdecor/src/workbench.lua:133'
2017-09-20 14:24:33: ERROR[Main]:   Local variables:
2017-09-20 14:24:33: ERROR[Main]:    self = table: 0x00b0c7c8  {get_output:function: 0x00b110e8, on_take:function: 0x00b11598, repairable:function: 0x00b110c8, timer:function: 0x00b11368, move:function: 0x00b11558, defs:table: 0x00b10190, construct:function: 0x00b11220, fields:function: 0x
2017-09-20 14:24:33: ERROR[Main]: 0b11328, set_formspec:function: 0x00b111e0, dig:function: 0x00b11348, put:function: 0x00b11388, on_put:function: 0x00b11578}
2017-09-20 14:24:33: ERROR[Main]:    meta = userdata: 0x008998e0
2017-09-20 14:24:33: ERROR[Main]:    id = nil
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = C function: 0x0000c850
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = userdata: 0x008998e0
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = string: "formspec"
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = string: "size[8,7;]list[current_player;main;0,3.25;8,4;]"
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = nil
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = string: "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.png;true]listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]image[0,3.25;1,1;gui_hb_bg.png]image[1,3.25;1,1;gui_hb_bg.png]image[2,3.25;1,1;gui_hb_bg.png]image[3,3.25;1,1;gui_hb_
2017-09-20 14:24:33: ERROR[Main]: g.png]image[4,3.25;1,1;gui_hb_bg.png]image[5,3.25;1,1;gui_hb_bg.png]image[6,3.25;1,1;gui_hb_bg.png]image[7,3.25;1,1;gui_hb_bg.png]"
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = string: "image[0,3.25;1,1;gui_hb_bg.png]image[1,3.25;1,1;gui_hb_bg.png]image[2,3.25;1,1;gui_hb_bg.png]image[3,3.25;1,1;gui_hb_bg.png]image[4,3.25;1,1;gui_hb_bg.png]image[5,3.25;1,1;gui_hb_bg.png]image[6,3.25;1,1;gui_hb_bg.png]image[7,3.25
2017-09-20 14:24:33: ERROR[Main]: 1,1;gui_hb_bg.png]"
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = number: 0
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = number: 3.25
2017-09-20 14:24:33: ERROR[Main]:    (*temporary) = string: "attempt to concatenate a nil value"
2017-09-20 14:24:33: ERROR[Main]: (3) Lua function 'workbench' at file '/home/UGX/.minetest/games/UGXrealms/mods/xdecor/src/workbench.lua:153' (best guess)
2017-09-20 14:24:33: ERROR[Main]:   Local variables:
2017-09-20 14:24:33: ERROR[Main]:    pos = table: 0x002d5af8  {y:19, x:16543, z:20249}
2017-09-20 14:24:33: ERROR[Main]:    _ = string: ""
2017-09-20 14:24:33: ERROR[Main]:    fields = table: 0x00c850b0  {key_up:true}
2017-09-20 14:24:33: ERROR[Main]:    meta = userdata: 0x008998e0

:large_orange_diamond:

sofar commented 7 years ago

Confirmed, I just had this same crash on a server.

sofar commented 7 years ago

id = nil in your crash, assuming those values are the lua function parameters, which looks correct. This would cause the table index to be nil. Testing shows that table[nil] returns nil, so there is somehow an incorrect value passed for id somewhere.

sofar commented 7 years ago

https://github.com/minetest-mods/xdecor/blob/master/src/workbench.lua#L155

If the player uses keyup or something like that, none of the fields.craft etc. are set. Causing nil to be passed as id.

Something like this may fix it:

diff --git a/xdecor/src/workbench.lua b/xdecor/src/workbench.lua
index 0df3bf5..80a4c5e 100644
--- a/xdecor/src/workbench.lua
+++ b/xdecor/src/workbench.lua
@@ -150,9 +150,11 @@ end
 function workbench.fields(pos, _, fields)
        if fields.quit then return end
        local meta = minetest.get_meta(pos)
-       workbench:set_formspec(meta, fields.back    and 1 or
-                                    fields.craft   and 2 or
-                                    fields.storage and 3)
+       local id = fields.back and 1 or
+                  fields.craft and 2 or
+                  fields.storage and 3
+       if not id then return end
+       workbench:set_formspec(meta, id)
 end

 function workbench.dig(pos)
kilbith commented 7 years ago

@sofar Feel free to push it. I don't code for xdecor anymore.

ahkok commented 7 years ago

Yes, I'm verifying my fix later today and will push once I get a chance to test it.