From 768a329cde5466803e8eaabec9bc87ebda8dc439 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Tue, 10 Sep 2024 22:09:59 +0200 Subject: [PATCH] Common/ChunkEntities: Add lock guard around invalidated chunks --- include/CommonLib/ChunkEntities.hpp | 1 + src/CommonLib/ChunkEntities.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/CommonLib/ChunkEntities.hpp b/include/CommonLib/ChunkEntities.hpp index b6e9794..52336fa 100644 --- a/include/CommonLib/ChunkEntities.hpp +++ b/include/CommonLib/ChunkEntities.hpp @@ -78,6 +78,7 @@ namespace tsom NazaraSlot(ChunkContainer, OnChunkUpdated, m_onChunkUpdated); NazaraSlot(Nz::Node, OnNodeInvalidation, m_onParentNodeInvalidated); + std::mutex m_invalidatedChunkMutex; entt::handle m_parentEntity; tsl::hopscotch_map m_invalidatedChunks; tsl::hopscotch_map> m_updateJobs; diff --git a/src/CommonLib/ChunkEntities.cpp b/src/CommonLib/ChunkEntities.cpp index 8784d41..db1b734 100644 --- a/src/CommonLib/ChunkEntities.cpp +++ b/src/CommonLib/ChunkEntities.cpp @@ -42,6 +42,8 @@ namespace tsom m_onChunkUpdated.Connect(chunkContainer.OnChunkUpdated, [this](ChunkContainer* /*emitter*/, Chunk* chunk, DirectionMask neighborMask) { + // Chunks can be updated in parallel (e.g. planet generation) + std::lock_guard lock(m_invalidatedChunkMutex); m_invalidatedChunks[chunk->GetIndices()] |= neighborMask; }); }