summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNovatux <nathanael.courant@laposte.net>2015-08-01 16:36:50 +0200
committerNovatux <nathanael.courant@laposte.net>2015-08-01 16:36:50 +0200
commit4eeb6950c45dea9b35e3485c194ac31280befe66 (patch)
tree85b24ceac2686e86a98dba7e9a5edbdd804e12e2
parentbedcf4d6467c987a1ef29088d363f9cea1b095db (diff)
downloadpipeworks-4eeb6950c45dea9b35e3485c194ac31280befe66.tar
pipeworks-4eeb6950c45dea9b35e3485c194ac31280befe66.tar.gz
pipeworks-4eeb6950c45dea9b35e3485c194ac31280befe66.tar.bz2
pipeworks-4eeb6950c45dea9b35e3485c194ac31280befe66.tar.xz
pipeworks-4eeb6950c45dea9b35e3485c194ac31280befe66.zip
Fix crash when deleting luaentities with //clearobjects.
-rw-r--r--default_settings.txt2
-rw-r--r--luaentity.lua31
2 files changed, 24 insertions, 9 deletions
diff --git a/default_settings.txt b/default_settings.txt
index a95038d..bbf02ce 100644
--- a/default_settings.txt
+++ b/default_settings.txt
@@ -18,3 +18,5 @@ pipeworks.enable_mese_sand_tube = true
pipeworks.enable_one_way_tube = true
pipeworks.enable_priority_tube = true
pipeworks.enable_cyclic_mode = true
+
+pipeworks.delete_item_on_clearobject = true \ No newline at end of file
diff --git a/luaentity.lua b/luaentity.lua
index 4ecb163..665e055 100644
--- a/luaentity.lua
+++ b/luaentity.lua
@@ -149,8 +149,8 @@ local entitydef_default = {
_remove_attached = function(self, index)
local master = self._attached_entities_master
local entity = self._attached_entities[index]
- local ent = entity.entity
- entity.entity = nil
+ local ent = entity and entity.entity
+ if entity then entity.entity = nil end
if index == master then
self:_detach_all()
local newmaster
@@ -315,10 +315,11 @@ minetest.register_globalstep(function(dtime)
end
for id, entity in pairs(luaentity.entities) do
local master = entity._attached_entities_master
- if master then
- local master_def = entity._attached_entities[master]
- local master_entity = master_def.entity
- entity._pos = vector.subtract(master_entity:getpos(), master_def.offset)
+ local master_def = master and entity._attached_entities[master]
+ local master_entity = master_def and master_def.entity
+ local master_entity_pos = master_entity and master_entity:getpos()
+ if master_entity_pos then
+ entity._pos = vector.subtract(master_entity_pos, master_def.offset)
entity._velocity = master_entity:getvelocity()
entity._acceleration = master_entity:getacceleration()
else
@@ -330,9 +331,21 @@ minetest.register_globalstep(function(dtime)
entity._velocity,
vector.multiply(entity._acceleration, dtime))
end
- entity:_add_loaded()
- if entity.on_step then
- entity:on_step(dtime)
+ if master and not master_entity_pos then -- The entity has somehow been cleared
+ if pipeworks.delete_item_on_clearobject then
+ entity:remove()
+ else
+ entity:_remove_attached(master)
+ entity:_add_loaded()
+ if entity.on_step then
+ entity:on_step(dtime)
+ end
+ end
+ else
+ entity:_add_loaded()
+ if entity.on_step then
+ entity:on_step(dtime)
+ end
end
end
end)