SFTtech / openage

Free (as in freedom) open source clone of the Age of Empires II engine 🚀
http://openage.dev
Other
12.79k stars 1.13k forks source link

Fix thread-safe access for render entities #1692

Closed heinezen closed 3 weeks ago

heinezen commented 1 month ago

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.

https://github.com/SFTtech/openage/blob/66098cea4d799634d66b0e9b9691fdf715a7118d/libopenage/renderer/stages/world/render_entity.cpp#L63-L67

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: