Skip to content

Commit 03fd671

Browse files
committed
renderer: Fix lock of resource reads in render entity.
1 parent b1dfe87 commit 03fd671

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

libopenage/renderer/stages/world/object.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void WorldObject::fetch_updates(const time::time_t &time) {
6262
}
6363

6464
// Get data from render entity
65+
auto read_lock = this->render_entity->get_read_lock();
6566
this->ref_id = this->render_entity->get_id();
6667
this->position.sync(this->render_entity->get_position());
6768
this->animation_info.sync(this->render_entity->get_animation_path(),
@@ -78,6 +79,7 @@ void WorldObject::fetch_updates(const time::time_t &time) {
7879
}),
7980
this->last_update);
8081
this->angle.sync(this->render_entity->get_angle(), this->last_update);
82+
read_lock.unlock();
8183

8284
// Set self to changed so that world renderer can update the renderable
8385
this->changed = true;

libopenage/renderer/stages/world/render_entity.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ void WorldRenderEntity::clear_changed_flag() {
9696
this->changed = false;
9797
}
9898

99+
std::shared_lock<std::shared_mutex> WorldRenderEntity::get_read_lock() {
100+
return std::shared_lock{this->mutex};
101+
}
102+
99103
} // namespace openage::renderer::world

libopenage/renderer/stages/world/render_entity.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <cstdint>
66
#include <list>
7+
#include <mutex>
78
#include <shared_mutex>
89
#include <string>
910

@@ -105,6 +106,13 @@ class WorldRenderEntity {
105106
*/
106107
void clear_changed_flag();
107108

109+
/**
110+
* Get a lock for thread-safe reading from the render entity.
111+
*
112+
* @return Lock for the render entity.
113+
*/
114+
std::shared_lock<std::shared_mutex> get_read_lock();
115+
108116
private:
109117
/**
110118
* Flag for determining if the render entity has been updated by the

0 commit comments

Comments
 (0)