Skip to content

Commit 0b448f1

Browse files
authored
fix(client_openxr): 🐛 Fix crash on unsupported eye tracking permission on Pico (#2618)
1 parent 23ce975 commit 0b448f1

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use openxr::{self as xr, sys};
2+
use std::ptr;
3+
4+
fn get_props<G, T>(session: &xr::Session<G>, system: xr::SystemId, default_struct: T) -> Option<T> {
5+
let instance = session.instance();
6+
7+
let mut props = default_struct;
8+
let mut system_properties = sys::SystemProperties::out((&mut props as *mut T).cast());
9+
let result = unsafe {
10+
(instance.fp().get_system_properties)(
11+
instance.as_raw(),
12+
system,
13+
system_properties.as_mut_ptr(),
14+
)
15+
};
16+
(result.into_raw() >= 0).then_some(props)
17+
}
18+
19+
pub fn supports_eye_gaze_interaction<G>(session: &xr::Session<G>, system: xr::SystemId) -> bool {
20+
if session.instance().exts().ext_eye_gaze_interaction.is_none() {
21+
return false;
22+
}
23+
24+
get_props(
25+
session,
26+
system,
27+
sys::SystemEyeGazeInteractionPropertiesEXT {
28+
ty: sys::SystemEyeGazeInteractionPropertiesEXT::TYPE,
29+
next: ptr::null_mut(),
30+
supports_eye_gaze_interaction: sys::FALSE,
31+
},
32+
)
33+
.map(|props| props.supports_eye_gaze_interaction.into())
34+
.unwrap_or(false)
35+
}

alvr/client_openxr/src/extra_extensions/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod body_tracking_fb;
2+
mod eye_gaze_interaction;
23
mod eye_tracking_social;
34
mod face_tracking2_fb;
45
mod facial_tracking_htc;
@@ -7,6 +8,7 @@ mod passthrough_fb;
78
mod passthrough_htc;
89

910
pub use body_tracking_fb::*;
11+
pub use eye_gaze_interaction::*;
1012
pub use eye_tracking_social::*;
1113
pub use face_tracking2_fb::*;
1214
pub use facial_tracking_htc::*;

alvr/client_openxr/src/interaction.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub struct InteractionContext {
116116
impl InteractionContext {
117117
pub fn new(
118118
xr_session: xr::Session<xr::OpenGlEs>,
119+
xr_system: xr::SystemId,
119120
platform: Platform,
120121
supports_multimodal: bool,
121122
) -> Self {
@@ -270,9 +271,13 @@ impl InteractionContext {
270271
)
271272
.unwrap();
272273

273-
let combined_eyes_source = if xr_instance.exts().ext_eye_gaze_interaction.is_some()
274-
&& !platform.is_quest()
274+
// Pico headsets require calling get_system_properties to test for extensions, because all
275+
// extensions function pointers are available even if the feature is not supported by the
276+
// hardware. The full checks are done in supports_eye_gaze_interaction. This is required
277+
// to avoid a crash when requesting the EYE_TRACKING permission.
278+
let combined_eyes_source = if !platform.is_quest()
275279
&& !platform.is_vive()
280+
&& extra_extensions::supports_eye_gaze_interaction(&xr_session, xr_system)
276281
{
277282
#[cfg(target_os = "android")]
278283
if platform.is_pico() {

alvr/client_openxr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub fn entry_point() {
267267

268268
let interaction_context = Arc::new(RwLock::new(InteractionContext::new(
269269
xr_session.clone(),
270+
xr_system,
270271
platform,
271272
exts.other
272273
.contains(&META_SIMULTANEOUS_HANDS_AND_CONTROLLERS_EXTENSION_NAME.to_owned()),

0 commit comments

Comments
 (0)