diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index c3962980698..e0e58e5f099 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -107,6 +107,8 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::unique_ptrgetTile(x, y); } + std::unique_lock l(floor->getMutex()); + const uint8_t z = floor->getZ(); auto map = static_cast(this); diff --git a/src/map/mapcache.hpp b/src/map/mapcache.hpp index 7dda032b78b..6265e979fa4 100644 --- a/src/map/mapcache.hpp +++ b/src/map/mapcache.hpp @@ -86,6 +86,7 @@ struct Floor { z(z) {}; std::shared_ptr getTile(uint16_t x, uint16_t y) const { + std::shared_lock sl(mutex); return tiles[x & FLOOR_MASK][y & FLOOR_MASK].first; } @@ -94,6 +95,7 @@ struct Floor { } std::shared_ptr getTileCache(uint16_t x, uint16_t y) const { + std::shared_lock sl(mutex); return tiles[x & FLOOR_MASK][y & FLOOR_MASK].second; } @@ -105,8 +107,13 @@ struct Floor { return z; } + auto &getMutex() const { + return mutex; + } + private: std::pair, std::shared_ptr> tiles[FLOOR_SIZE][FLOOR_SIZE] = {}; + mutable std::shared_mutex mutex; uint8_t z { 0 }; };