Fix thread-safe access for render entities #1692
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current render entity code was not thread-safe because of an oversight in the implementation. When syncing data between the render entity and the objects in the renderer, sometimes references were passed instead of copying the data over, e.g.
openage/libopenage/renderer/stages/world/render_entity.cpp
Lines 63 to 67 in 66098ce
After returning the reference, the lock is released even though a read has not taken place yet. This results in the simulation thread writing data into the render entity while it is still being read, with the consequence that over- or underreads might happen. I fixed this behavior now by ensuring that locks are present for the full read duration.
Changes in this PR:
get_read_lock()
which returns astd::shared_lock
locking the render entity's mutex. This allows manual control of data reads from the render entity.renderer::RenderEntity
base class for the shared functionality of the different render entity types in HUD, terrain, and world render stages.