summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2015-06-23 12:24:35 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2015-06-23 12:48:20 -0400
commitd0952a97fcff08328328d05f630d2b0036a48163 (patch)
tree671699a26e5f46c73b56d5eb8756abee466f3ed4
parent5822f60ba9cbebe45c1f82fa06dc93b747ba71a6 (diff)
downloadpipeworks-d0952a97fcff08328328d05f630d2b0036a48163.tar
pipeworks-d0952a97fcff08328328d05f630d2b0036a48163.tar.gz
pipeworks-d0952a97fcff08328328d05f630d2b0036a48163.tar.bz2
pipeworks-d0952a97fcff08328328d05f630d2b0036a48163.tar.xz
pipeworks-d0952a97fcff08328328d05f630d2b0036a48163.zip
fix multiple crash points if luaentity.entities or values returned from
luaentity.add_entity() are nil
-rw-r--r--item_transport.lua1
-rw-r--r--luaentity.lua6
2 files changed, 7 insertions, 0 deletions
diff --git a/item_transport.lua b/item_transport.lua
index fb9f626..7b64e7a 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -6,6 +6,7 @@ function pipeworks.tube_inject_item(pos, start_pos, velocity, item)
-- Take item in any format
local stack = ItemStack(item)
local obj = luaentity.add_entity(pos, "pipeworks:tubed_item")
+ if not obj then return end
obj:set_item(stack:to_string())
obj.start_pos = vector.new(start_pos)
obj:setvelocity(velocity)
diff --git a/luaentity.lua b/luaentity.lua
index 241da14..9be0f3a 100644
--- a/luaentity.lua
+++ b/luaentity.lua
@@ -22,6 +22,7 @@ end
local function read_entities()
local t = read_file()
+ if not t then return end
for _, entity in pairs(t) do
setmetatable(entity, luaentity.registered_entities[entity.name])
end
@@ -29,6 +30,7 @@ local function read_entities()
end
local function write_entities()
+ if not luaentity.entities then return end
for _, entity in pairs(luaentity.entities) do
setmetatable(entity, nil)
for _, attached in pairs(entity._attached_entities) do
@@ -251,6 +253,7 @@ end
-- end
function luaentity.add_entity(pos, name)
+ if not luaentity.entities then return end
local index = luaentity.entities_index
while luaentity.entities[index] do
index = index + 1
@@ -281,6 +284,7 @@ end
-- todo: check if remove in get_staticdata works
function luaentity.get_staticdata(self)
+ if not luaentity.entities then return end
local parent = luaentity.entities[self.parent_id]
if parent and parent._remove_attached then
parent:_remove_attached(self.attached_id)
@@ -295,6 +299,7 @@ function luaentity.on_activate(self, staticdata)
end
function luaentity.get_objects_inside_radius(pos, radius)
+ if not luaentity.entities then return end
local objects = {}
local index = 1
for id, entity in pairs(luaentity.entities) do
@@ -309,6 +314,7 @@ minetest.register_globalstep(function(dtime)
if not luaentity.entities then
luaentity.entities = read_entities()
end
+ if not luaentity.entities then return end
for id, entity in pairs(luaentity.entities) do
local master = entity._attached_entities_master
if master then