mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-15 17:35:37 +02: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:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user