Merge pull request #127 from Schmarni-Dev/fix_non_xr_compat

Fix crashes when running without an openxr runtime
This commit is contained in:
ForTehLose
2024-06-28 13:12:49 -04:00
committed by GitHub
2 changed files with 10 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
use std::{mem, ptr}; use std::{mem, ptr};
use bevy::prelude::*; use bevy::prelude::*;
use bevy_xr::session::session_available;
use openxr::sys; use openxr::sys;
use crate::{ use crate::{
@@ -15,7 +16,7 @@ impl Plugin for OxrOverlayPlugin {
fn build(&self, app: &mut bevy::prelude::App) { fn build(&self, app: &mut bevy::prelude::App) {
app.add_event::<OxrOverlaySessionEvent>(); app.add_event::<OxrOverlaySessionEvent>();
app.init_resource::<OxrOverlaySettings>(); app.init_resource::<OxrOverlaySettings>();
app.add_systems(First, add_overlay_info_to_chain); app.add_systems(First, add_overlay_info_to_chain.run_if(session_available));
} }
} }

View File

@@ -58,6 +58,7 @@ use bevy_openxr::{
action_binding::OxrSuggestActionBinding, action_set_attaching::OxrAttachActionSet, action_binding::OxrSuggestActionBinding, action_set_attaching::OxrAttachActionSet,
resources::OxrInstance, session::OxrSession, resources::OxrInstance, session::OxrSession,
}; };
use bevy_xr::session::{session_available, session_running};
use openxr::{ActiveActionSet, Path, Vector2f}; use openxr::{ActiveActionSet, Path, Vector2f};
use std::borrow::Cow; use std::borrow::Cow;
@@ -66,30 +67,29 @@ impl Plugin for XRUtilsActionsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems( app.add_systems(
Startup, Startup,
create_openxr_events.in_set(XRUtilsActionSystemSet::CreateEvents), create_openxr_events
); .in_set(XRUtilsActionSystemSet::CreateEvents)
app.add_systems( .run_if(session_available),
Update,
sync_active_action_sets.run_if(resource_exists::<OxrSession>),
); );
app.add_systems(Update, sync_active_action_sets.run_if(session_running));
app.add_systems( app.add_systems(
Update, Update,
sync_and_update_action_states_f32 sync_and_update_action_states_f32
.run_if(resource_exists::<OxrSession>) .run_if(session_running)
.in_set(XRUtilsActionSystemSet::SyncActionStates) .in_set(XRUtilsActionSystemSet::SyncActionStates)
.after(sync_active_action_sets), .after(sync_active_action_sets),
); );
app.add_systems( app.add_systems(
Update, Update,
sync_and_update_action_states_bool sync_and_update_action_states_bool
.run_if(resource_exists::<OxrSession>) .run_if(session_running)
.in_set(XRUtilsActionSystemSet::SyncActionStates) .in_set(XRUtilsActionSystemSet::SyncActionStates)
.after(sync_active_action_sets), .after(sync_active_action_sets),
); );
app.add_systems( app.add_systems(
Update, Update,
sync_and_update_action_states_vector sync_and_update_action_states_vector
.run_if(resource_exists::<OxrSession>) .run_if(session_running)
.in_set(XRUtilsActionSystemSet::SyncActionStates) .in_set(XRUtilsActionSystemSet::SyncActionStates)
.after(sync_active_action_sets), .after(sync_active_action_sets),
); );