From fdde32283afd1327a09872214b09a611002e95fa Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 31 Dec 2017 18:21:44 -0700 Subject: [PATCH] add logging and crash-proofing for issue 17 A user has reported a crash that appears to involve a builder node (group 4) that lacks a "main" inventory somehow. This code prevents a crash in this circumstance and logs the node_image to hopefully identify the culprit. --- class_layout.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/class_layout.lua b/class_layout.lua index df4a3d5..cf9a7bb 100644 --- a/class_layout.lua +++ b/class_layout.lua @@ -18,12 +18,18 @@ local get_node_image = function(pos, node) -- Record what kind of thing we've got in a builder node so its facing can be rotated properly if minetest.get_item_group(node.name, "digtron") == 4 then - local build_item = node_image.meta.inventory.main[1] - if build_item ~= "" then - local build_item_def = minetest.registered_nodes[ItemStack(build_item):get_name()] - if build_item_def ~= nil then - node_image.build_item_paramtype2 = build_item_def.paramtype2 + -- https://github.com/minetest-mods/digtron/issues/17 had a user encounter a crash here, + -- adding logging to hopefully catch it if it happens again. + if node_image.meta.inventory.main ~= nil then + local build_item = node_image.meta.inventory.main[1] + if build_item ~= "" then + local build_item_def = minetest.registered_nodes[ItemStack(build_item):get_name()] + if build_item_def ~= nil then + node_image.build_item_paramtype2 = build_item_def.paramtype2 + end end + else + minetest.log("error", string.format("Digtron node in group 4 lacks a 'main' inventory. Please update the issue at https://github.com/minetest-mods/digtron/issues/17. Node image: %s", dump(node_image))) end end return node_image