1
0
mirror of https://github.com/minetest/minetest_game.git synced 2024-12-22 15:00:18 +01:00

Fix crash on exit of bed formspec if not sleeping (#2826)

This commit is contained in:
Lars Müller 2021-02-11 12:30:37 +01:00 committed by GitHub
parent 3d95fceee8
commit 624dafc12b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,18 +60,19 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- stand up -- stand up
if state ~= nil and not state then if state ~= nil and not state then
local p = beds.pos[name] or nil if not beds.player[name] then
-- player not in bed, do nothing
return false
end
beds.bed_position[name] = nil beds.bed_position[name] = nil
-- skip here to prevent sending player specific changes (used for leaving players) -- skip here to prevent sending player specific changes (used for leaving players)
if skip then if skip then
return return
end end
if p then player:set_pos(beds.pos[name])
player:set_pos(p)
end
-- physics, eye_offset, etc -- physics, eye_offset, etc
local physics_override = assert(beds.player[name].physics_override) local physics_override = beds.player[name].physics_override
beds.player[name] = nil beds.player[name] = nil
player:set_physics_override({ player:set_physics_override({
speed = physics_override.speed, speed = physics_override.speed,
@ -101,6 +102,11 @@ local function lay_down(player, pos, bed_pos, state, skip)
return false return false
end end
if beds.player[name] then
-- player already in bed, do nothing
return false
end
beds.pos[name] = pos beds.pos[name] = pos
beds.bed_position[name] = bed_pos beds.bed_position[name] = bed_pos
beds.player[name] = {physics_override = player:get_physics_override()} beds.player[name] = {physics_override = player:get_physics_override()}