Skip to content

Commit 40594b3

Browse files
committed
fixes #79, reduce crash possibility, not sure whether still got it yet
1 parent dff074a commit 40594b3

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

crates/notation_bevy/src/app/app.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,20 @@ fn setup_camera(mut commands: Commands) {
134134

135135
fn load_tab(
136136
mut state: ResMut<NotationAppState>,
137+
entities: Query<Entity, With<GlobalTransform>>,
137138
assets: ResMut<Assets<TabAsset>>,
138139
mut evts: EventWriter<AddTabEvent>,
139140
) {
140141
if state.window_width > 0.0 && state.window_height > 0.0 && state.tab.is_none() && state.parse_error.is_none() {
142+
let mut count = 0;
143+
for _ in entities.iter() {
144+
count += 1;
145+
}
146+
//A bit hacky to make sure despawning finished, otherwise might got panic with "Entity not exist"
147+
if count > 1 {
148+
println!("Waiting for entities to be despawned: {}", count);
149+
return;
150+
}
141151
if let Some(asset) = assets.get(&state.tab_asset) {
142152
match Tab::try_parse_arc(asset.tab.clone()) {
143153
Ok(tab) => {

crates/notation_bevy/src/guitar/guitar_string.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ impl ShapeOp<NotationTheme, OutlineRectangle> for GuitarStringData {
148148
shapes::RectangleOrigin::TopLeft
149149
};
150150
let color = if self.upper {
151-
theme
152-
.colors
153-
.strings
154-
.string
155-
.of_state(&PlayingState::Idle)
151+
if self.is_muted() {
152+
theme.colors.strings.muted
153+
} else {
154+
theme
155+
.colors
156+
.strings
157+
.string
158+
.of_state(&PlayingState::Idle)
159+
}
156160
} else if self.is_muted() {
157161
theme.colors.strings.muted
158162
} else if self.state.is_current() && self.note.is_some() {

crates/notation_bevy/src/viewer/control.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ impl ControlView {
9191
state: &mut NotationAppState,
9292
viewer_query: &Query<(Entity, &Arc<NotationViewer>), With<Arc<NotationViewer>>>,
9393
) {
94+
if state.tab.is_none() {
95+
return;
96+
}
9497
for (entity, viewer) in viewer_query.iter() {
9598
if viewer.uuid == state.viewer_uuid {
9699
commands.entity(entity).despawn_recursive();

0 commit comments

Comments
 (0)