Fix crash if add_entity fails (#88)

This commit is contained in:
savilli 2023-09-16 18:19:03 +02:00 committed by GitHub
parent d90c17edee
commit e7cba4071b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -163,11 +163,15 @@ local entitydef_default = {
if not is_active(entity_pos) then if not is_active(entity_pos) then
return return
end end
local ent = minetest.add_entity(entity_pos, entity.name):get_luaentity() local object = minetest.add_entity(entity_pos, entity.name)
if not object then
return
end
local ent = object:get_luaentity()
ent:from_data(entity.data) ent:from_data(entity.data)
ent.parent_id = self._id ent.parent_id = self._id
ent.attached_id = index ent.attached_id = index
entity.entity = ent.object entity.entity = object
local master = self._attached_entities_master local master = self._attached_entities_master
if master then if master then
self:_attach(index, master) self:_attach(index, master)