From e2928a742452feff092740ca47c63b9092795de3 Mon Sep 17 00:00:00 2001 From: SniperJoe Date: Mon, 6 May 2024 12:28:28 +0300 Subject: [PATCH] Fix a couple of segfaults on linux (#2108) * lots of fixes * remove unique_ptr from matInv33 * debug output removings * remove unwanted formatting * remove unwanted formatting * fix formatting attempt * remove cache --------- Co-authored-by: Nikita Morozov --- .../cpp/alvr_server/ChaperoneUpdater.cpp | 40 +++++++++---- alvr/server/cpp/alvr_server/alvr_server.cpp | 2 +- .../cpp/alvr_server/include/openvr_math.h | 56 +++++++++---------- wiki/Building-From-Source.md | 2 +- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp index 2877ffc57f..f20f485ef7 100644 --- a/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp +++ b/alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp @@ -71,16 +71,27 @@ void _SetChaperoneArea(float areaWidth, float areaHeight) { perimeterPoints[3][0] = 1.0f * areaWidth; perimeterPoints[3][1] = -1.0f * areaHeight; - vr::VRChaperoneSetup()->SetWorkingPerimeter( - reinterpret_cast(perimeterPoints), 4); - vr::VRChaperoneSetup()->SetWorkingStandingZeroPoseToRawTrackingPose(&MATRIX_IDENTITY); - vr::VRChaperoneSetup()->SetWorkingSeatedZeroPoseToRawTrackingPose(&MATRIX_IDENTITY); - vr::VRChaperoneSetup()->SetWorkingPlayAreaSize(areaWidth, areaHeight); - vr::VRChaperoneSetup()->CommitWorkingCopy(vr::EChaperoneConfigFile_Live); - - // Hide SteamVR Chaperone - vr::VRSettings()->SetFloat( - vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_FadeDistance_Float, 0.0f); + auto setup = vr::VRChaperoneSetup(); + + if (setup != nullptr) + { + vr::VRChaperoneSetup()->SetWorkingPerimeter( + reinterpret_cast(perimeterPoints), 4); + vr::VRChaperoneSetup()->SetWorkingStandingZeroPoseToRawTrackingPose(&MATRIX_IDENTITY); + vr::VRChaperoneSetup()->SetWorkingSeatedZeroPoseToRawTrackingPose(&MATRIX_IDENTITY); + vr::VRChaperoneSetup()->SetWorkingPlayAreaSize(areaWidth, areaHeight); + vr::VRChaperoneSetup()->CommitWorkingCopy(vr::EChaperoneConfigFile_Live); + } + + auto settings = vr::VRSettings(); + + if (settings != nullptr) + { + // Hide SteamVR Chaperone + vr::VRSettings()->SetFloat( + vr::k_pch_CollisionBounds_Section, vr::k_pch_CollisionBounds_FadeDistance_Float, 0.0f); + } + #endif } @@ -91,10 +102,15 @@ std::unique_ptr GetInvZeroPose() { { return nullptr; } - std::unique_ptr mat; + auto mat = std::make_unique(); // revert pulls live into working copy vr::VRChaperoneSetup()->RevertWorkingCopy(); - if (vr::VRCompositor()->GetTrackingSpace() == vr::TrackingUniverseStanding) { + auto compositor = vr::VRCompositor(); + if (compositor == nullptr) + { + return nullptr; + } + if (compositor->GetTrackingSpace() == vr::TrackingUniverseStanding) { vr::VRChaperoneSetup()->GetWorkingStandingZeroPoseToRawTrackingPose(mat.get()); } else { vr::VRChaperoneSetup()->GetWorkingSeatedZeroPoseToRawTrackingPose(mat.get()); diff --git a/alvr/server/cpp/alvr_server/alvr_server.cpp b/alvr/server/cpp/alvr_server/alvr_server.cpp index 05b556f039..29599dafa0 100644 --- a/alvr/server/cpp/alvr_server/alvr_server.cpp +++ b/alvr/server/cpp/alvr_server/alvr_server.cpp @@ -33,7 +33,7 @@ std::unique_ptr GetRawZeroPose() { { return nullptr; } - return vrmath::matInv33(std::move(invZeroPose)); + return std::make_unique(vrmath::matInv33(*invZeroPose)); } bool IsOpenvrClientReady(); diff --git a/alvr/server/cpp/alvr_server/include/openvr_math.h b/alvr/server/cpp/alvr_server/include/openvr_math.h index 1a6993d0bb..8374e17c66 100644 --- a/alvr/server/cpp/alvr_server/include/openvr_math.h +++ b/alvr/server/cpp/alvr_server/include/openvr_math.h @@ -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(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; } diff --git a/wiki/Building-From-Source.md b/wiki/Building-From-Source.md index 4d42edd98d..e395402641 100644 --- a/wiki/Building-From-Source.md +++ b/wiki/Building-From-Source.md @@ -36,7 +36,7 @@ If you are on Linux, install these additional packages: * **Debian 12 / Ubuntu 20.04 / Pop!\_OS 20.04** ```bash - sudo apt install build-essential pkg-config libclang-dev libssl-dev libasound2-dev libjack-dev libgtk-3-dev libvulkan-dev libunwind-dev gcc yasm nasm curl libx264-dev libx265-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libdrm-dev libva-dev libvulkan-dev vulkan-headers + sudo apt install pulseaudio-utils build-essential pkg-config libclang-dev libssl-dev libasound2-dev libjack-dev libgtk-3-dev libvulkan-dev libunwind-dev gcc yasm nasm curl libx264-dev libx265-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libspeechd-dev libxkbcommon-dev libdrm-dev libva-dev libvulkan-dev vulkan-headers ``` * **Fedora**