Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EguiUserTextures related crash when gui feature is nabled and bevy-egui is used #442

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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