From 0e5e49736c0a5fa29bca257bafc02d7c7a7171c9 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Sun, 22 Mar 2015 20:09:44 +0100 Subject: 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 --- src/player.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/player.h') diff --git a/src/player.h b/src/player.h index def428847..f38bd5615 100644 --- a/src/player.h +++ b/src/player.h @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_bloated.h" #include "inventory.h" #include "constants.h" // BS +#include "jthread/jmutexautolock.h" #include #define PLAYERNAME_SIZE 20 @@ -202,7 +203,8 @@ public: return m_collisionbox; } - u32 getFreeHudID() const { + u32 getFreeHudID() { + JMutexAutoLock lock(m_mutex); size_t size = hud.size(); for (size_t i = 0; i != size; i++) { if (!hud[i]) @@ -318,6 +320,11 @@ protected: bool m_dirty; std::vector hud; +private: + // Protect some critical areas + // hud for example can be modified by EmergeThread + // and ServerThread + JMutex m_mutex; }; -- cgit v1.2.3