From 8446cd0abf1ba9c61f34758728a90aca67e9d4d2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:35:02 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20Fix=20potential=20panics=20on=20?= =?UTF-8?q?UI=20button=20interactions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces unsafe `unwrap()` and index array access `children[0]` with safe `let-else` patterns in Bevy UI button interaction systems. This prevents application crashes (Denial of Service) when interacting with buttons that lack children or a `Text` component. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- src/ui/systems.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ui/systems.rs b/src/ui/systems.rs index 88e2ffb..7f1fbf7 100644 --- a/src/ui/systems.rs +++ b/src/ui/systems.rs @@ -28,7 +28,8 @@ pub fn sequence_control_button_system( mut rhythm_state: ResMut, ) { for (interaction, mut background_color, children) in &mut interaction_query { - let mut text = text_query.get_mut(children[0]).unwrap(); + let Some(&child) = children.first() else { continue; }; + let Ok(mut text) = text_query.get_mut(child) else { continue; }; match *interaction { Interaction::Pressed => { sequence_state.running = !sequence_state.running; @@ -67,7 +68,8 @@ pub fn curriculum_toggle_system( mut sequence_state: ResMut, ) { for (interaction, mut background_color, children) in &mut interaction_query { - let mut text = text_query.get_mut(children[0]).unwrap(); + let Some(&child) = children.first() else { continue; }; + let Ok(mut text) = text_query.get_mut(child) else { continue; }; match *interaction { Interaction::Pressed => { curriculum_state.is_visible = !curriculum_state.is_visible; @@ -102,7 +104,8 @@ pub fn mode_toggle_system( mut sequence_state: ResMut, ) { for (interaction, mut background_color, children) in &mut interaction_query { - let mut text = text_query.get_mut(children[0]).unwrap(); + let Some(&child) = children.first() else { continue; }; + let Ok(mut text) = text_query.get_mut(child) else { continue; }; match *interaction { Interaction::Pressed => { sequence_state.mode = match sequence_state.mode { @@ -146,7 +149,8 @@ pub fn rhythm_mode_toggle_system( mut rhythm_state: ResMut, ) { for (interaction, mut background_color, children) in &mut interaction_query { - let mut text = text_query.get_mut(children[0]).unwrap(); + let Some(&child) = children.first() else { continue; }; + let Ok(mut text) = text_query.get_mut(child) else { continue; }; match *interaction { Interaction::Pressed => { rhythm_state.mode = match rhythm_state.mode {