From 40594b3f90d038b594030a3156300b5762a5e611 Mon Sep 17 00:00:00 2001 From: YJ Park Date: Sun, 12 Dec 2021 18:38:43 +0800 Subject: [PATCH] fixes #79, reduce crash possibility, not sure whether still got it yet --- crates/notation_bevy/src/app/app.rs | 10 ++++++++++ crates/notation_bevy/src/guitar/guitar_string.rs | 14 +++++++++----- crates/notation_bevy/src/viewer/control.rs | 3 +++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/notation_bevy/src/app/app.rs b/crates/notation_bevy/src/app/app.rs index 6f0c0cda..84d510d1 100644 --- a/crates/notation_bevy/src/app/app.rs +++ b/crates/notation_bevy/src/app/app.rs @@ -134,10 +134,20 @@ fn setup_camera(mut commands: Commands) { fn load_tab( mut state: ResMut, + entities: Query>, assets: ResMut>, mut evts: EventWriter, ) { if state.window_width > 0.0 && state.window_height > 0.0 && state.tab.is_none() && state.parse_error.is_none() { + let mut count = 0; + for _ in entities.iter() { + count += 1; + } + //A bit hacky to make sure despawning finished, otherwise might got panic with "Entity not exist" + if count > 1 { + println!("Waiting for entities to be despawned: {}", count); + return; + } if let Some(asset) = assets.get(&state.tab_asset) { match Tab::try_parse_arc(asset.tab.clone()) { Ok(tab) => { diff --git a/crates/notation_bevy/src/guitar/guitar_string.rs b/crates/notation_bevy/src/guitar/guitar_string.rs index ad4e0b21..5eb92b14 100644 --- a/crates/notation_bevy/src/guitar/guitar_string.rs +++ b/crates/notation_bevy/src/guitar/guitar_string.rs @@ -148,11 +148,15 @@ impl ShapeOp for GuitarStringData { shapes::RectangleOrigin::TopLeft }; let color = if self.upper { - theme - .colors - .strings - .string - .of_state(&PlayingState::Idle) + if self.is_muted() { + theme.colors.strings.muted + } else { + theme + .colors + .strings + .string + .of_state(&PlayingState::Idle) + } } else if self.is_muted() { theme.colors.strings.muted } else if self.state.is_current() && self.note.is_some() { diff --git a/crates/notation_bevy/src/viewer/control.rs b/crates/notation_bevy/src/viewer/control.rs index 9f0437c1..0858bff9 100644 --- a/crates/notation_bevy/src/viewer/control.rs +++ b/crates/notation_bevy/src/viewer/control.rs @@ -91,6 +91,9 @@ impl ControlView { state: &mut NotationAppState, viewer_query: &Query<(Entity, &Arc), With>>, ) { + if state.tab.is_none() { + return; + } for (entity, viewer) in viewer_query.iter() { if viewer.uuid == state.viewer_uuid { commands.entity(entity).despawn_recursive();