Sometimes HUD can be modified by ServerThread and EmergeThread results in a crash on client side because the HUD is not correct
u32 Player::addHud(HudElement *toadd)
{
+ JMutexAutoLock lock(m_mutex);
u32 id = getFreeHudID();
if (id < hud.size())
HudElement* Player::getHud(u32 id)
{
+ JMutexAutoLock lock(m_mutex);
+
if (id < hud.size())
return hud[id];
HudElement* Player::removeHud(u32 id)
{
+ JMutexAutoLock lock(m_mutex);
+
HudElement* retval = NULL;
if (id < hud.size()) {
retval = hud[id];
void Player::clearHud()
{
+ JMutexAutoLock lock(m_mutex);
+
while(!hud.empty()) {
delete hud.back();
hud.pop_back();
#include "irrlichttypes_bloated.h"
#include "inventory.h"
#include "constants.h" // BS
+#include "jthread/jmutexautolock.h"
#include <list>
#define PLAYERNAME_SIZE 20
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])
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;
};