Skip to content

Commit

Permalink
Revert "Fix linux segfault (#2090)"
Browse files Browse the repository at this point in the history
This reverts commit de235ea.
  • Loading branch information
galister committed May 6, 2024
1 parent 989823c commit 6bba363
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 56 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
14 changes: 4 additions & 10 deletions alvr/server/cpp/alvr_server/ChaperoneUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Logger.h"
#include "bindings.h"
#include <mutex>
#include <memory>

#ifndef __APPLE__
// Workaround symbol clash in openvr.h / openvr_driver.h
Expand Down Expand Up @@ -85,19 +84,14 @@ void _SetChaperoneArea(float areaWidth, float areaHeight) {
}

#ifdef __linux__
std::unique_ptr<vr::HmdMatrix34_t> GetInvZeroPose() {
std::unique_lock<std::mutex> lock(chaperone_mutex);
if (!isOpenvrInit)
{
return nullptr;
}
std::unique_ptr<vr::HmdMatrix34_t> 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;
}
Expand Down
18 changes: 5 additions & 13 deletions alvr/server/cpp/alvr_server/alvr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@

#ifdef __linux__
#include "include/openvr_math.h"
std::unique_ptr<vr::HmdMatrix34_t> GetInvZeroPose();
vr::HmdMatrix34_t GetInvZeroPose();

std::unique_ptr<vr::HmdMatrix34_t> 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();
Expand Down Expand Up @@ -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
Expand Down
58 changes: 29 additions & 29 deletions alvr/server/cpp/alvr_server/include/openvr_math.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <cmath>
#include <memory>


inline vr::HmdQuaternion_t operator+(const vr::HmdQuaternion_t& lhs, const vr::HmdQuaternion_t& rhs) {
return {
Expand Down Expand Up @@ -298,42 +298,42 @@ namespace vrmath {
return result;
}

inline std::unique_ptr<vr::HmdMatrix34_t> matInv33(std::unique_ptr<vr::HmdMatrix34_t> matrix) {
std::unique_ptr<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];
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<vr::HmdMatrix34_t>(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;
}
Expand Down

0 comments on commit 6bba363

Please sign in to comment.