Skip to content

Commit

Permalink
added a mutex around the write and size-check/read calls so we don't …
Browse files Browse the repository at this point in the history
…continue to expose a race condition on the s_lastRenderInfo vector.
  • Loading branch information
DuFF14 committed Feb 17, 2017
1 parent d7916a7 commit 126519a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions OsvrRenderingPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ enum RenderEvents {
kOsvrEventID_ClearRoomToWorldTransform = 4
};

// Mutex provides thread safety when accessing s_lastRenderInfo from Unity
std::mutex m_mutex;

// --------------------------------------------------------------------------
// Helper utilities

Expand Down Expand Up @@ -321,6 +324,7 @@ void UNITY_INTERFACE_API UnityPluginUnload() {
}

inline void UpdateRenderInfo() {
std::lock_guard<std::mutex> lock(m_mutex);
s_renderInfo = s_render->GetRenderInfo(s_renderParams);
if (s_renderInfo.size() > 0)
{
Expand Down Expand Up @@ -683,15 +687,18 @@ void UNITY_INTERFACE_API SetIPD(double ipdMeters) {

osvr::renderkit::OSVR_ViewportDescription UNITY_INTERFACE_API
GetViewport(int eye) {
std::lock_guard<std::mutex> lock(m_mutex);
return s_lastRenderInfo[eye].viewport;
}

osvr::renderkit::OSVR_ProjectionMatrix UNITY_INTERFACE_API
GetProjectionMatrix(int eye) {
std::lock_guard<std::mutex> lock(m_mutex);
return s_lastRenderInfo[eye].projection;
}

OSVR_Pose3 UNITY_INTERFACE_API GetEyePose(int eye) {
std::lock_guard<std::mutex> lock(m_mutex);
return s_lastRenderInfo[eye].pose;
}

Expand Down

0 comments on commit 126519a

Please sign in to comment.