Skip to content

Commit

Permalink
Fix egui feature EguiUserTexturesCrash
Browse files Browse the repository at this point in the history
  • Loading branch information
mrafaj committed Jan 9, 2024
1 parent 9b7e9c3 commit 5c6aa38
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::action_state::ActionDiffEvent;
#[cfg(feature = "ui")]
use bevy::ui::Interaction;
#[cfg(feature = "egui")]
use bevy_egui::EguiContexts;
use bevy_egui::EguiContext;

/// Advances actions timer.
///
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn update_action_state<A: Actionlike>(
#[cfg(all(feature = "ui", feature = "block_ui_interactions"))] interactions: Query<
&Interaction,
>,
#[cfg(feature = "egui")] mut maybe_egui: EguiContexts,
#[cfg(feature = "egui")] mut maybe_egui: Query<(Entity, &'static mut EguiContext)>,
action_state: Option<ResMut<ActionState<A>>>,
input_map: Option<Res<InputMap<A>>>,
press_scheduler: Option<ResMut<PressScheduler<A>>>,
Expand Down Expand Up @@ -111,12 +111,12 @@ pub fn update_action_state<A: Actionlike>(
(mouse_buttons, mouse_wheel)
};

#[cfg(feature = "egui")]
let ctx = maybe_egui.ctx_mut();

// If egui wants to own inputs, don't also apply them to the game state
#[cfg(feature = "egui")]
let (keycodes, scan_codes) = if ctx.wants_keyboard_input() {
let (keycodes, scan_codes) = if maybe_egui
.iter_mut()
.any(|(_, mut ctx)| ctx.get_mut().wants_keyboard_input())
{
(None, None)
} else {
(keycodes, scan_codes)
Expand All @@ -125,7 +125,9 @@ pub fn update_action_state<A: Actionlike>(
// `wants_pointer_input` sometimes returns `false` after clicking or holding a button over a widget,
// so `is_pointer_over_area` is also needed.
#[cfg(feature = "egui")]
let (mouse_buttons, mouse_wheel) = if ctx.is_pointer_over_area() || ctx.wants_pointer_input() {
let (mouse_buttons, mouse_wheel) = if maybe_egui.iter_mut().any(|(_, mut ctx)| {
ctx.get_mut().is_pointer_over_area() || ctx.get_mut().wants_pointer_input()
}) {
(None, None)
} else {
(mouse_buttons, mouse_wheel)
Expand Down

0 comments on commit 5c6aa38

Please sign in to comment.