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; }); }