Skip to content

Commit

Permalink
feat(client_openxr): 🔊 Log extensions errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 21, 2024
1 parent eaea406 commit a46b271
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 97 deletions.
21 changes: 14 additions & 7 deletions alvr/client_openxr/src/extra_extensions/body_tracking_fb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]

use alvr_common::{anyhow::Result, once_cell::sync::Lazy, ToAny};
use alvr_common::once_cell::sync::Lazy;
use openxr::{self as xr, raw, sys};
use std::ptr;

Expand Down Expand Up @@ -37,8 +37,15 @@ pub struct BodyTrackerFB {
}

impl BodyTrackerFB {
pub fn new<G>(session: &xr::Session<G>, body_joint_set: xr::BodyJointSetFB) -> Result<Self> {
let ext_fns = session.instance().exts().fb_body_tracking.to_any()?;
pub fn new<G>(
session: &xr::Session<G>,
body_joint_set: xr::BodyJointSetFB,
) -> xr::Result<Self> {
let ext_fns = session
.instance()
.exts()
.fb_body_tracking
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

let mut handle = sys::BodyTrackerFB::NULL;
let info = sys::BodyTrackerCreateInfoFB {
Expand All @@ -47,11 +54,11 @@ impl BodyTrackerFB {
body_joint_set,
};
unsafe {
super::xr_to_any((ext_fns.create_body_tracker)(
super::xr_res((ext_fns.create_body_tracker)(
session.as_raw(),
&info,
&mut handle,
))?
))?;
};

Ok(Self { handle, ext_fns })
Expand All @@ -62,7 +69,7 @@ impl BodyTrackerFB {
time: xr::Time,
reference_space: &xr::Space,
joint_count: usize,
) -> Result<Option<Vec<xr::BodyJointLocationFB>>> {
) -> xr::Result<Option<Vec<xr::BodyJointLocationFB>>> {
let locate_info = sys::BodyJointsLocateInfoFB {
ty: sys::BodyJointsLocateInfoFB::TYPE,
next: ptr::null(),
Expand All @@ -81,7 +88,7 @@ impl BodyTrackerFB {
time: xr::Time::from_nanos(0),
};
unsafe {
super::xr_to_any((self.ext_fns.locate_body_joints)(
super::xr_res((self.ext_fns.locate_body_joints)(
self.handle,
&locate_info,
&mut location_info,
Expand Down
15 changes: 9 additions & 6 deletions alvr/client_openxr/src/extra_extensions/eye_tracking_social.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alvr_common::{anyhow::Result, ToAny};
use openxr::{self as xr, raw, sys};
use std::ptr;

Expand All @@ -8,16 +7,20 @@ pub struct EyeTrackerSocial {
}

impl EyeTrackerSocial {
pub fn new<G>(session: &xr::Session<G>) -> Result<Self> {
let ext_fns = session.instance().exts().fb_eye_tracking_social.to_any()?;
pub fn new<G>(session: &xr::Session<G>) -> xr::Result<Self> {
let ext_fns = session
.instance()
.exts()
.fb_eye_tracking_social
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

let mut handle = sys::EyeTrackerFB::NULL;
let info = sys::EyeTrackerCreateInfoFB {
ty: sys::EyeTrackerCreateInfoFB::TYPE,
next: ptr::null(),
};
unsafe {
super::xr_to_any((ext_fns.create_eye_tracker)(
super::xr_res((ext_fns.create_eye_tracker)(
session.as_raw(),
&info,
&mut handle,
Expand All @@ -31,7 +34,7 @@ impl EyeTrackerSocial {
&self,
base: &xr::Space,
time: xr::Time,
) -> Result<[Option<xr::Posef>; 2]> {
) -> xr::Result<[Option<xr::Posef>; 2]> {
let gaze_info = sys::EyeGazesInfoFB {
ty: sys::EyeGazesInfoFB::TYPE,
next: ptr::null(),
Expand All @@ -42,7 +45,7 @@ impl EyeTrackerSocial {
let mut eye_gazes = sys::EyeGazesFB::out(ptr::null_mut());

let eye_gazes = unsafe {
super::xr_to_any((self.ext_fns.get_eye_gazes)(
super::xr_res((self.ext_fns.get_eye_gazes)(
self.handle,
&gaze_info,
eye_gazes.as_mut_ptr(),
Expand Down
15 changes: 9 additions & 6 deletions alvr/client_openxr/src/extra_extensions/face_tracking2_fb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alvr_common::{anyhow::Result, ToAny};
use openxr::{self as xr, raw, sys};
use std::ptr;

Expand All @@ -8,8 +7,12 @@ pub struct FaceTracker2FB {
}

impl FaceTracker2FB {
pub fn new<G>(session: &xr::Session<G>, visual: bool, audio: bool) -> Result<Self> {
let ext_fns = session.instance().exts().fb_face_tracking2.to_any()?;
pub fn new<G>(session: &xr::Session<G>, visual: bool, audio: bool) -> xr::Result<Self> {
let ext_fns = session
.instance()
.exts()
.fb_face_tracking2
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

let mut requested_data_sources = vec![];
if visual {
Expand All @@ -28,7 +31,7 @@ impl FaceTracker2FB {
requested_data_sources: requested_data_sources.as_mut_ptr(),
};
unsafe {
super::xr_to_any((ext_fns.create_face_tracker2)(
super::xr_res((ext_fns.create_face_tracker2)(
session.as_raw(),
&info,
&mut handle,
Expand All @@ -38,7 +41,7 @@ impl FaceTracker2FB {
Ok(Self { handle, ext_fns })
}

pub fn get_face_expression_weights(&self, time: xr::Time) -> Result<Option<Vec<f32>>> {
pub fn get_face_expression_weights(&self, time: xr::Time) -> xr::Result<Option<Vec<f32>>> {
let expression_info = sys::FaceExpressionInfo2FB {
ty: sys::FaceExpressionInfo2FB::TYPE,
next: ptr::null(),
Expand All @@ -65,7 +68,7 @@ impl FaceTracker2FB {
};

unsafe {
super::xr_to_any((self.ext_fns.get_face_expression_weights2)(
super::xr_res((self.ext_fns.get_face_expression_weights2)(
self.handle,
&expression_info,
&mut expression_weights,
Expand Down
15 changes: 9 additions & 6 deletions alvr/client_openxr/src/extra_extensions/facial_tracking_htc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alvr_common::{anyhow::Result, ToAny};
use openxr::{self as xr, raw, sys};
use std::ptr;

Expand All @@ -12,8 +11,12 @@ impl FacialTrackerHTC {
pub fn new<G>(
session: &xr::Session<G>,
facial_tracking_type: xr::FacialTrackingTypeHTC,
) -> Result<Self> {
let ext_fns = session.instance().exts().htc_facial_tracking.to_any()?;
) -> xr::Result<Self> {
let ext_fns = session
.instance()
.exts()
.htc_facial_tracking
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

let mut handle = sys::FacialTrackerHTC::NULL;
let info = sys::FacialTrackerCreateInfoHTC {
Expand All @@ -22,7 +25,7 @@ impl FacialTrackerHTC {
facial_tracking_type,
};
unsafe {
super::xr_to_any((ext_fns.create_facial_tracker)(
super::xr_res((ext_fns.create_facial_tracker)(
session.as_raw(),
&info,
&mut handle,
Expand All @@ -42,7 +45,7 @@ impl FacialTrackerHTC {
})
}

pub fn get_facial_expressions(&self) -> Result<Option<Vec<f32>>> {
pub fn get_facial_expressions(&self) -> xr::Result<Option<Vec<f32>>> {
let mut weights = Vec::with_capacity(self.expression_count);

let mut facial_expressions = sys::FacialExpressionsHTC {
Expand All @@ -55,7 +58,7 @@ impl FacialTrackerHTC {
};

unsafe {
super::xr_to_any((self.ext_fns.get_facial_expressions)(
super::xr_res((self.ext_fns.get_facial_expressions)(
self.handle,
&mut facial_expressions,
))?;
Expand Down
7 changes: 3 additions & 4 deletions alvr/client_openxr/src/extra_extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ pub use face_tracking2_fb::*;
pub use facial_tracking_htc::*;
pub use multimodal_input::*;

use alvr_common::anyhow::{anyhow, Result};
use openxr::sys;
use openxr::{self as xr, sys};

fn xr_to_any(result: sys::Result) -> Result<()> {
fn xr_res(result: sys::Result) -> xr::Result<()> {
if result.into_raw() >= 0 {
Ok(())
} else {
Err(anyhow!("OpenXR error: {:?}", result))
Err(result)
}
}
15 changes: 8 additions & 7 deletions alvr/client_openxr/src/extra_extensions/multimodal_input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Code taken from:
// https://github.com/meta-quest/Meta-OpenXR-SDK/blob/main/OpenXR/meta_openxr_preview/meta_simultaneous_hands_and_controllers.h

use alvr_common::{anyhow::Result, once_cell::sync::Lazy, ToAny};
use alvr_common::once_cell::sync::Lazy;
use openxr::{
self as xr,
sys::{self, pfn::VoidFunction},
Expand Down Expand Up @@ -29,7 +29,7 @@ pub type ResumeSimultaneousHandsAndControllersTrackingMETA =

pub fn resume_simultaneous_hands_and_controllers_tracking<G>(
session: &xr::Session<G>,
) -> Result<()> {
) -> xr::Result<()> {
let resume_simultaneous_hands_and_controllers_tracking_meta = unsafe {
let mut resume_simultaneous_hands_and_controllers_tracking_meta = None;
let _ = (session.instance().fp().get_instance_proc_addr)(
Expand All @@ -38,18 +38,19 @@ pub fn resume_simultaneous_hands_and_controllers_tracking<G>(
&mut resume_simultaneous_hands_and_controllers_tracking_meta,
);

mem::transmute::<VoidFunction, ResumeSimultaneousHandsAndControllersTrackingMETA>(
resume_simultaneous_hands_and_controllers_tracking_meta.to_any()?,
)
};
resume_simultaneous_hands_and_controllers_tracking_meta.map(|pfn| {
mem::transmute::<VoidFunction, ResumeSimultaneousHandsAndControllersTrackingMETA>(pfn)
})
}
.ok_or(sys::Result::ERROR_EXTENSION_NOT_PRESENT)?;

let resume_info = SimultaneousHandsAndControllersTrackingResumeInfoMETA {
ty: *TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_RESUME_INFO_META,
next: ptr::null(),
};

unsafe {
super::xr_to_any(resume_simultaneous_hands_and_controllers_tracking_meta(
super::xr_res(resume_simultaneous_hands_and_controllers_tracking_meta(
session.as_raw(),
&resume_info,
))?;
Expand Down
Loading

0 comments on commit a46b271

Please # to comment.