Server crash question

For people working on the C++ code.
User avatar
joe7575
Member
 
Posts: 231
Joined: Mon Apr 24, 2017 20:38
Location: Germany, in the deep south
GitHub: joe7575
In-game: JoSto

Server crash question

by joe7575 » Fri Apr 13, 2018 17:36

This small script leads to a server crash when the player leaves the game.
Code: Select all
local function jail_player(pos, player)
   if pos and player then
      player:setpos(pos)   
      minetest.after(1, jail_player, pos, player)
   end
end

minetest.register_on_joinplayer(function(player)
   local pos = player:getpos()
   jail_player(pos, player)
end)


The player object is still valid, but the player is already gone. A call to player:setpos(pos) leads to a memory access error:
Code: Select all
2018-04-13 19:23:22: ACTION[Server]: JoSto leaves game. List of players:
Speicherzugriffsfehler (Speicherabzug geschrieben)


I use: Minetest 0.4.16 (Linux)

Is this a core issue or a modding fault?
Sent from my Commodore 64. My Mods: TechPack, Hyperloop, Tower Crane, Lumberjack, Iron Age, Entrance.
 

User avatar
Krock
Developer
 
Posts: 4106
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: Server crash question

by Krock » Fri Apr 13, 2018 18:07

Modding fault. Never use an ObjectRef outside the scope of the callback function. Instead of passing the player object to your "jail_player" function, use the player name and run "minetest.get_player_name(name)" to check whether the player is still online.

Hint: If you attach the player to an invisible, indestructible object on join and occasionally after each player's death, the player can't move at all.
Mod Search Engine - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
rubenwardy
Moderator
 
Posts: 5470
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
 

User avatar
joe7575
Member
 
Posts: 231
Joined: Mon Apr 24, 2017 20:38
Location: Germany, in the deep south
GitHub: joe7575
In-game: JoSto

Re: Server crash question

by joe7575 » Fri Apr 13, 2018 18:55

Thanks, I got it. (...RTFM)
@Knock: This was only a simple example to explain the problem, not a real use case.
Sent from my Commodore 64. My Mods: TechPack, Hyperloop, Tower Crane, Lumberjack, Iron Age, Entrance.
 

User avatar
rubenwardy
Moderator
 
Posts: 5470
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Server crash question

by rubenwardy » Fri Apr 13, 2018 18:56

Another thing: it's set_pos not setpos. The method has been renamed (since like 0.4.14 or smth) :)
 


Return to Partly official engine development



Who is online

Users browsing this forum: No registered users and 2 guests