summaryrefslogtreecommitdiff
path: root/src/player.cpp
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-03-22 20:09:44 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-22 20:47:07 +0100
commit0e5e49736c0a5fa29bca257bafc02d7c7a7171c9 (patch)
tree87d7e19f8082099f2570d8094ba75167cf5a7f35 /src/player.cpp
parentd6638b4300b091275fa25c43eaee42cd6d13effe (diff)
downloadminetest-0e5e49736c0a5fa29bca257bafc02d7c7a7171c9.tar.gz
minetest-0e5e49736c0a5fa29bca257bafc02d7c7a7171c9.tar.bz2
minetest-0e5e49736c0a5fa29bca257bafc02d7c7a7171c9.zip
Protect Player::hud from concurrent modifications
Sometimes HUD can be modified by ServerThread and EmergeThread results in a crash on client side because the HUD is not correct
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 0da761eed..88c5634e3 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -240,6 +240,7 @@ void Player::deSerialize(std::istream &is, std::string playername)
u32 Player::addHud(HudElement *toadd)
{
+ JMutexAutoLock lock(m_mutex);
u32 id = getFreeHudID();
if (id < hud.size())
@@ -252,6 +253,8 @@ u32 Player::addHud(HudElement *toadd)
HudElement* Player::getHud(u32 id)
{
+ JMutexAutoLock lock(m_mutex);
+
if (id < hud.size())
return hud[id];
@@ -260,6 +263,8 @@ HudElement* Player::getHud(u32 id)
HudElement* Player::removeHud(u32 id)
{
+ JMutexAutoLock lock(m_mutex);
+
HudElement* retval = NULL;
if (id < hud.size()) {
retval = hud[id];
@@ -270,6 +275,8 @@ HudElement* Player::removeHud(u32 id)
void Player::clearHud()
{
+ JMutexAutoLock lock(m_mutex);
+
while(!hud.empty()) {
delete hud.back();
hud.pop_back();