Skip to content

Commit

Permalink
fix(client_openxr): 🐛 Fix crash caused by undefined behavior (#2391)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp authored Sep 13, 2024
1 parent 3e2f9d6 commit 74924a2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
12 changes: 9 additions & 3 deletions alvr/client_openxr/src/extra_extensions/eye_tracking_social.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ impl super::ExtraExtensions {
instance: &xr::Instance,
system: xr::SystemId,
) -> bool {
self.get_props(instance, system, unsafe {
sys::SystemEyeTrackingPropertiesFB::out(ptr::null_mut()).assume_init()
})
self.get_props(
instance,
system,
sys::SystemEyeTrackingPropertiesFB {
ty: sys::SystemEyeTrackingPropertiesFB::TYPE,
next: ptr::null_mut(),
supports_eye_tracking: sys::FALSE,
},
)
.map(|props| props.supports_eye_tracking.into())
.unwrap_or(false)
}
Expand Down
23 changes: 13 additions & 10 deletions alvr/client_openxr/src/extra_extensions/face_tracking2_fb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ use alvr_common::{anyhow::Result, ToAny};
use openxr::{self as xr, raw, sys};
use std::ptr;

const DEFAULT_PROPS: sys::SystemFaceTrackingProperties2FB = sys::SystemFaceTrackingProperties2FB {
ty: sys::SystemFaceTrackingProperties2FB::TYPE,
next: ptr::null_mut(),
supports_visual_face_tracking: sys::FALSE,
supports_audio_face_tracking: sys::FALSE,
};

impl super::ExtraExtensions {
pub fn supports_fb_visual_face_tracking(
&self,
instance: &xr::Instance,
system: xr::SystemId,
) -> bool {
self.get_props(instance, system, unsafe {
sys::SystemFaceTrackingProperties2FB::out(ptr::null_mut()).assume_init()
})
.map(|props| props.supports_visual_face_tracking.into())
.unwrap_or(false)
self.get_props(instance, system, DEFAULT_PROPS)
.map(|props| props.supports_visual_face_tracking.into())
.unwrap_or(false)
}

pub fn supports_fb_audio_face_tracking(
&self,
instance: &xr::Instance,
system: xr::SystemId,
) -> bool {
self.get_props(instance, system, unsafe {
sys::SystemFaceTrackingProperties2FB::out(ptr::null_mut()).assume_init()
})
.map(|props| props.supports_audio_face_tracking.into())
.unwrap_or(false)
self.get_props(instance, system, DEFAULT_PROPS)
.map(|props| props.supports_audio_face_tracking.into())
.unwrap_or(false)
}

pub fn create_face_tracker2_fb<G>(
Expand Down
24 changes: 14 additions & 10 deletions alvr/client_openxr/src/extra_extensions/facial_tracking_htc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,33 @@ use alvr_common::{anyhow::Result, ToAny};
use openxr::{self as xr, raw, sys};
use std::ptr;

const DEFAULT_PROPS: sys::SystemFacialTrackingPropertiesHTC =
sys::SystemFacialTrackingPropertiesHTC {
ty: sys::SystemFacialTrackingPropertiesHTC::TYPE,
next: ptr::null_mut(),
support_eye_facial_tracking: sys::FALSE,
support_lip_facial_tracking: sys::FALSE,
};

impl super::ExtraExtensions {
pub fn supports_htc_eye_facial_tracking(
&self,
instance: &xr::Instance,
system: xr::SystemId,
) -> bool {
self.get_props(instance, system, unsafe {
sys::SystemFacialTrackingPropertiesHTC::out(ptr::null_mut()).assume_init()
})
.map(|props| props.support_eye_facial_tracking.into())
.unwrap_or(false)
self.get_props(instance, system, DEFAULT_PROPS)
.map(|props| props.support_eye_facial_tracking.into())
.unwrap_or(false)
}

pub fn supports_htc_lip_facial_tracking(
&self,
instance: &xr::Instance,
system: xr::SystemId,
) -> bool {
self.get_props(instance, system, unsafe {
sys::SystemFacialTrackingPropertiesHTC::out(ptr::null_mut()).assume_init()
})
.map(|props| props.support_lip_facial_tracking.into())
.unwrap_or(false)
self.get_props(instance, system, DEFAULT_PROPS)
.map(|props| props.support_lip_facial_tracking.into())
.unwrap_or(false)
}

pub fn create_facial_tracker_htc<G>(
Expand Down
6 changes: 3 additions & 3 deletions alvr/client_openxr/src/extra_extensions/multimodal_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

pub const META_SIMULTANEOUS_HANDS_AND_CONTROLLERS_EXTENSION_NAME: &str =
"XR_META_simultaneous_hands_and_controllers";
Expand Down Expand Up @@ -44,7 +44,7 @@ impl super::ExtraExtensions {
system,
SystemSymultaneousHandsAndControllersPropertiesMETA {
ty: *TYPE_SYSTEM_SIMULTANEOUS_HANDS_AND_CONTROLLERS_PROPERTIES_META,
next: std::ptr::null(),
next: ptr::null(),
supports_simultaneous_hands_and_controllers: xr::sys::FALSE,
},
)
Expand All @@ -58,7 +58,7 @@ impl super::ExtraExtensions {
) -> Result<()> {
let resume_info = SimultaneousHandsAndControllersTrackingResumeInfoMETA {
ty: *TYPE_SIMULTANEOUS_HANDS_AND_CONTROLLERS_TRACKING_RESUME_INFO_META,
next: std::ptr::null(),
next: ptr::null(),
};

unsafe {
Expand Down

0 comments on commit 74924a2

Please sign in to comment.