Skip to content

Commit

Permalink
fixes #79, reduce crash possibility, not sure whether still got it yet
Browse files Browse the repository at this point in the history
  • Loading branch information
yjpark committed Dec 12, 2021
1 parent dff074a commit 40594b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions crates/notation_bevy/src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,20 @@ fn setup_camera(mut commands: Commands) {

fn load_tab(
mut state: ResMut<NotationAppState>,
entities: Query<Entity, With<GlobalTransform>>,
assets: ResMut<Assets<TabAsset>>,
mut evts: EventWriter<AddTabEvent>,
) {
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) => {
Expand Down
14 changes: 9 additions & 5 deletions crates/notation_bevy/src/guitar/guitar_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ impl ShapeOp<NotationTheme, OutlineRectangle> 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() {
Expand Down
3 changes: 3 additions & 0 deletions crates/notation_bevy/src/viewer/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ impl ControlView {
state: &mut NotationAppState,
viewer_query: &Query<(Entity, &Arc<NotationViewer>), With<Arc<NotationViewer>>>,
) {
if state.tab.is_none() {
return;
}
for (entity, viewer) in viewer_query.iter() {
if viewer.uuid == state.viewer_uuid {
commands.entity(entity).despawn_recursive();
Expand Down

0 comments on commit 40594b3

Please sign in to comment.