From 6bba36335ca9bea19e6cf7414ff51059f2291c8d Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Mon, 6 May 2024 12:13:41 +0900 Subject: [PATCH] Revert "Fix linux segfault (#2090)" This reverts commit de235ea2f1acdd12da04924dce3adcc634afdf8b. --- .gitignore | 4 -- .../cpp/alvr_server/ChaperoneUpdater.cpp | 14 ++--- alvr/server/cpp/alvr_server/alvr_server.cpp | 18 ++---- .../cpp/alvr_server/include/openvr_math.h | 58 +++++++++---------- 4 files changed, 38 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 4b66fc5315..f6ef4c3f64 100644 --- a/.gitignore +++ b/.gitignore @@ -67,7 +67,3 @@ node_modules .flatpak* ALVR-Launcher - -#allows adding CMake files for some IDEs to parse C++ files correctly -CMakeLists.txt -cmake-build-debug/ \ No newline at end of file diff --git a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp index 2877ffc57f..704f999a6c 100644 --- a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp +++ b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp @@ -2,7 +2,6 @@ #include "Logger.h" #include "bindings.h" #include -#include #ifndef __APPLE__ // Workaround symbol clash in openvr.h / openvr_driver.h @@ -85,19 +84,14 @@ void _SetChaperoneArea(float areaWidth, float areaHeight) { } #ifdef __linux__ -std::unique_ptr GetInvZeroPose() { - std::unique_lock lock(chaperone_mutex); - if (!isOpenvrInit) - { - return nullptr; - } - std::unique_ptr mat; +vr::HmdMatrix34_t GetInvZeroPose() { + vr::HmdMatrix34_t mat; // revert pulls live into working copy vr::VRChaperoneSetup()->RevertWorkingCopy(); if (vr::VRCompositor()->GetTrackingSpace() == vr::TrackingUniverseStanding) { - vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(mat.get()); + vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(&mat); } else { - vr::VRChaperoneSetup()->GetWorkingSeatedZeroPoseToRawTrackingPose(mat.get()); + vr::VRChaperoneSetup()->GetWorkingSeatedZeroPoseToRawTrackingPose(&mat); } return mat; } diff --git a/alvr/server/cpp/alvr_server/alvr_server.cpp b/alvr/server/cpp/alvr_server/alvr_server.cpp index 05b556f039..434abe46fa 100644 --- a/alvr/server/cpp/alvr_server/alvr_server.cpp +++ b/alvr/server/cpp/alvr_server/alvr_server.cpp @@ -25,15 +25,10 @@ #ifdef __linux__ #include "include/openvr_math.h" -std::unique_ptr GetInvZeroPose(); +vr::HmdMatrix34_t GetInvZeroPose(); -std::unique_ptr GetRawZeroPose() { - auto invZeroPose = GetInvZeroPose(); - if (invZeroPose == nullptr) - { - return nullptr; - } - return vrmath::matInv33(std::move(invZeroPose)); +vr::HmdMatrix34_t GetRawZeroPose() { + return vrmath::matInv33(GetInvZeroPose()); } bool IsOpenvrClientReady(); @@ -232,11 +227,8 @@ class DriverProvider : public vr::IServerTrackedDeviceProvider { || event.eventType == vr::VREvent_StandingZeroPoseReset || event.eventType == vr::VREvent_SceneApplicationChanged || event.eventType == VendorEvent_ALVRDriverResync) { - if (hmd && hmd->m_poseHistory) { - auto rawZeroPose = GetRawZeroPose(); - if (rawZeroPose != nullptr) { - hmd->m_poseHistory->SetTransform(*rawZeroPose); - } + if (hmd && hmd->m_poseHistory && IsOpenvrClientReady()) { + hmd->m_poseHistory->SetTransform(GetRawZeroPose()); } } #endif diff --git a/alvr/server/cpp/alvr_server/include/openvr_math.h b/alvr/server/cpp/alvr_server/include/openvr_math.h index 1a6993d0bb..2a7726f3c1 100644 --- a/alvr/server/cpp/alvr_server/include/openvr_math.h +++ b/alvr/server/cpp/alvr_server/include/openvr_math.h @@ -1,7 +1,7 @@ #pragma once #include -#include + inline vr::HmdQuaternion_t operator+(const vr::HmdQuaternion_t& lhs, const vr::HmdQuaternion_t& rhs) { return { @@ -298,42 +298,42 @@ namespace vrmath { return result; } - inline std::unique_ptr matInv33(std::unique_ptr matrix) { - std::unique_ptr result; - float cofac00 = matrix->m[1][1] * matrix->m[2][2] - matrix->m[1][2] * matrix->m[2][1]; - float cofac10 = matrix->m[1][2] * matrix->m[2][0] - matrix->m[1][0] * matrix->m[2][2]; - float cofac20 = matrix->m[1][0] * matrix->m[2][1] - matrix->m[1][1] * matrix->m[2][0]; + inline vr::HmdMatrix34_t matInv33(const vr::HmdMatrix34_t &matrix) { + vr::HmdMatrix34_t result; + float cofac00 = matrix.m[1][1] * matrix.m[2][2] - matrix.m[1][2] * matrix.m[2][1]; + float cofac10 = matrix.m[1][2] * matrix.m[2][0] - matrix.m[1][0] * matrix.m[2][2]; + float cofac20 = matrix.m[1][0] * matrix.m[2][1] - matrix.m[1][1] * matrix.m[2][0]; - float det = matrix->m[0][0] * cofac00 + matrix->m[0][1] * cofac10 + matrix->m[0][2] * cofac20; + float det = matrix.m[0][0] * cofac00 + matrix.m[0][1] * cofac10 + matrix.m[0][2] * cofac20; if (det == 0) { vr::HmdMatrix34_t result = { { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 } } }; - return std::make_unique(result); + return result; } float invDet = 1.0f / det; - float cofac01 = matrix->m[0][2] * matrix->m[2][1] - matrix->m[0][1] * matrix->m[2][2]; - float cofac02 = matrix->m[0][1] * matrix->m[1][2] - matrix->m[0][2] * matrix->m[1][1]; - float cofac11 = matrix->m[0][0] * matrix->m[2][2] - matrix->m[0][2] * matrix->m[2][0]; - float cofac12 = matrix->m[0][2] * matrix->m[1][0] - matrix->m[0][0] * matrix->m[1][2]; - float cofac21 = matrix->m[0][1] * matrix->m[2][0] - matrix->m[0][0] * matrix->m[2][1]; - float cofac22 = matrix->m[0][0] * matrix->m[1][1] - matrix->m[0][1] * matrix->m[1][0]; - - result->m[0][0] = invDet * cofac00; - result->m[0][1] = invDet * cofac01; - result->m[0][2] = invDet * cofac02; - result->m[0][3] = 0.0f; - - result->m[1][0] = invDet * cofac10; - result->m[1][1] = invDet * cofac11; - result->m[1][2] = invDet * cofac12; - result->m[1][3] = 0.0f; - - result->m[2][0] = invDet * cofac20; - result->m[2][1] = invDet * cofac21; - result->m[2][2] = invDet * cofac22; - result->m[2][3] = 0.0f; + float cofac01 = matrix.m[0][2] * matrix.m[2][1] - matrix.m[0][1] * matrix.m[2][2]; + float cofac02 = matrix.m[0][1] * matrix.m[1][2] - matrix.m[0][2] * matrix.m[1][1]; + float cofac11 = matrix.m[0][0] * matrix.m[2][2] - matrix.m[0][2] * matrix.m[2][0]; + float cofac12 = matrix.m[0][2] * matrix.m[1][0] - matrix.m[0][0] * matrix.m[1][2]; + float cofac21 = matrix.m[0][1] * matrix.m[2][0] - matrix.m[0][0] * matrix.m[2][1]; + float cofac22 = matrix.m[0][0] * matrix.m[1][1] - matrix.m[0][1] * matrix.m[1][0]; + + result.m[0][0] = invDet * cofac00; + result.m[0][1] = invDet * cofac01; + result.m[0][2] = invDet * cofac02; + result.m[0][3] = 0.0f; + + result.m[1][0] = invDet * cofac10; + result.m[1][1] = invDet * cofac11; + result.m[1][2] = invDet * cofac12; + result.m[1][3] = 0.0f; + + result.m[2][0] = invDet * cofac20; + result.m[2][1] = invDet * cofac21; + result.m[2][2] = invDet * cofac22; + result.m[2][3] = 0.0f; return result; }