1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

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
This commit is contained in:
Loic Blot 2015-03-22 20:09:44 +01:00
parent d6638b4300
commit 0e5e49736c
2 changed files with 15 additions and 1 deletions

View file

@ -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 <list>
#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<HudElement *> hud;
private:
// Protect some critical areas
// hud for example can be modified by EmergeThread
// and ServerThread
JMutex m_mutex;
};