Page 1 of 1

Bugfix for minetest.get_node_drops in builtin/item.lua

PostPosted: Thu Nov 01, 2012 00:13
by Orby
Forgot to post this sooner. I don't have the exact error message recorded, but I was getting periodic crashes due to a bug in minetest.get_node_drops (or a bug somewhere else that was passing bad data to minetest.get_node_drops that it was failing to handle appropriately). The culprit was line 113 in builtin/item.lua, the problem was that a nil value was passed to ipairs:

111 if good_rarity and good_tool then
112 got_count = got_count + 1
113 for _, add_item in ipairs(item.items) do
114 got_items[#got_items+1] = add_item
115 end
116 if drop.max_items ~= nil and got_count == drop.max_items then
117 break
118 end
119 end

which was easily fixed by adding

111 if good_rarity and good_tool and item.items ~= nil then
112 got_count = got_count + 1
113 for _, add_item in ipairs(item.items) do
114 got_items[#got_items+1] = add_item
115 end
116 if drop.max_items ~= nil and got_count == drop.max_items then
117 break
118 end
119 end

PostPosted: Thu Nov 01, 2012 11:26
by PilzAdam
Can you be more precise when its happening. If its realy a bug it should be fixed in upstream.

PostPosted: Thu Nov 01, 2012 17:16
by Orby
PilzAdam wrote:Can you be more precise when its happening. If its realy a bug it should be fixed in upstream.


I'd like to give specific conditions, but it was happening pretty randomly (once every couple days or so). It is a bug that should be fixed upstream. That particular statement shouldn't execute if item.items is nil, it'll just cause the game to crash.