refactor(client_player): return ChunkPosSet by value in non-const getter

Copy the internal set under the mutex lock to avoid exposing a mutable reference that could be used unsafely after the lock is released. This fixes a potential data race when the caller holds the returned reference beyond the critical section. Also update the caller in `client_world` to remove the now-unnecessary `std::move`.
This commit is contained in:
2026-07-10 18:41:52 +08:00
parent 1e30345c98
commit f8aac019bd
3 changed files with 3 additions and 3 deletions

View File

@@ -25,7 +25,7 @@ public:
void update_chunk_set(const ChunkPosSet& set);
const ChunkPosSet& get_chunk_pos_set() const;
ChunkPosSet& get_chunk_pos_set();
ChunkPosSet get_chunk_pos_set();
static AABB get_aabb(const glm::vec3& pos);
const glm::vec3& get_front() const;

View File

@@ -561,7 +561,7 @@ const ClientPlayer::ChunkPosSet& ClientPlayer::get_chunk_pos_set() const {
return m_player_chunk_pos_set;
}
ClientPlayer::ChunkPosSet& ClientPlayer::get_chunk_pos_set() {
ClientPlayer::ChunkPosSet ClientPlayer::get_chunk_pos_set() {
std::lock_guard lock(m_chunk_pos_mutex);
return m_player_chunk_pos_set;
}

View File

@@ -590,7 +590,7 @@ void ClientWorld::request_chunk() {
}
}
ChunkPosSet old = std::move(m_player.get_chunk_pos_set());
ChunkPosSet old = m_player.get_chunk_pos_set();
m_player.update_chunk_set(required_chunks);
ChunkPosVector need_send_pos;