Skip to content

Commit

Permalink
Fixed panicky queries
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian J. Hamel <[email protected]>
  • Loading branch information
simbleau and seabassjh committed Aug 21, 2023
1 parent a68f493 commit 97b993a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ fn draw_viewbox(
query_cam: Query<(&Camera, &GlobalTransform, &OrthographicProjection), With<Camera2d>>,
mut gizmos: Gizmos,
) {
const RED_X_SIZE: f32 = 8.0;
let Ok((camera, view, projection)) = query_cam.get_single() else { return };

let (camera, view, projection) = query_cam.single();
const RED_X_SIZE: f32 = 8.0;

// Show world-space vectors
for (vector, transform, _) in query_world
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ fn camera_system(
mut q: Query<&mut OrthographicProjection, With<Camera>>,
time: Res<Time>,
) {
let mut projection = q.single_mut();
let Ok(mut projection) = q.get_single_mut() else { return };
let Ok(mut camera_transform) = query_cam.get_single_mut() else { return };
let Ok((&(mut target_transform), vector)) = query.get_single_mut() else { return };

// Zoom in & out to demonstrate scalability and show the vector graphic's viewbox/anchor point
projection.scale = 2.0 * time.elapsed_seconds().cos();

let mut camera_transform = query_cam.single_mut();
let (&(mut target_transform), vector) = query.single_mut();
if let Some(vector) = vectors.get(&vector) {
target_transform.translation.y += vector.height * target_transform.scale.y / 2.0;
camera_transform.translation = target_transform.translation;
Expand All @@ -82,7 +82,7 @@ fn drag_and_drop(
asset_server: ResMut<AssetServer>,
mut dnd_evr: EventReader<FileDragAndDrop>,
) {
let (_, mut vector) = query.single_mut();
let Ok((_, mut vector)) = query.get_single_mut() else { return };

for ev in dnd_evr.iter() {
if let FileDragAndDrop::DroppedFile { path_buf, .. } = ev {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn prepare_vector_affines(
render_vector_assets: Res<RenderAssets<VelloVector>>,
pixel_scale: Res<ExtractedPixelScale>,
) {
let (camera, view) = camera.single();
let Ok((camera, view)) = camera.get_single() else { return };
let size_pixels: UVec2 = camera.physical_viewport_size.unwrap();
let (pixels_x, pixels_y) = (size_pixels.x as f32, size_pixels.y as f32);
for (entity, render_vector) in render_vectors.iter_mut() {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn prepare_text_affines(
render_texts: Query<(Entity, &ExtractedRenderText)>,
pixel_scale: Res<ExtractedPixelScale>,
) {
let (camera, view) = camera.single();
let Ok((camera, view)) = camera.get_single() else { return };
let size_pixels: UVec2 = camera.physical_viewport_size.unwrap();
let (pixels_x, pixels_y) = (size_pixels.x as f32, size_pixels.y as f32);
for (entity, render_text) in render_texts.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/rendertarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn resize_rendertargets(
mut target_materials: ResMut<Assets<SSTargetMaterial>>,
windows: Query<&Window>,
) {
let window = windows.single();
let Ok(window) = windows.get_single() else { return };
if window_resize_events.iter().last().is_some() {
let size = Extent3d {
width: window.resolution.physical_width(),
Expand Down Expand Up @@ -115,7 +115,7 @@ pub fn setup_ss_rendertarget(
// query_vectors: Query<Entity, Added<Handle<VelloVector>>>,
mut render_target_mesh_handle: Local<Option<Handle<Mesh>>>,
) {
let window = windows.single();
let Ok(window) = windows.get_single() else { return };

let mesh_handle = render_target_mesh_handle.get_or_insert_with(|| {
let mut rendertarget_quad = Mesh::new(PrimitiveTopology::TriangleList);
Expand Down

0 comments on commit 97b993a

Please sign in to comment.