Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Jan 30, 2024
1 parent 78ca0c2 commit 4a82926
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion avenger-vega/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn make_image_fetcher() -> Result<Box<dyn ImageFetcher>, AvengerVegaError> {
if #[cfg(feature = "image-request")] {
Ok(Box::new(ReqwestImageFetcher::new()))
} else {
Err(VegaSceneGraphError::NoImageFetcherConfigured(
Err(AvengerVegaError::NoImageFetcherConfigured(
"Image fetching requeres the image-reqwest feature flag".to_string()
))
}
Expand Down
30 changes: 24 additions & 6 deletions examples/scatter-panning/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use avenger::scene_graph::SceneGraph;
use avenger_vega::marks::symbol::shape_to_path;
use avenger_vega::scene_graph::VegaSceneGraph;
use avenger_wgpu::canvas::{Canvas, CanvasDimensions, WindowCanvas};
use avenger_wgpu::error::AvengerWgpuError;
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
Expand Down Expand Up @@ -149,13 +150,23 @@ pub async fn run() {
match canvas.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
canvas.resize(canvas.get_size())
Err(AvengerWgpuError::SurfaceError(err)) => {
match err {
wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated => {
canvas.resize(canvas.get_size());
}
wgpu::SurfaceError::OutOfMemory => {
// The system is out of memory, we should probably quit
*control_flow = ControlFlow::Exit;
}
wgpu::SurfaceError::Timeout => {
log::warn!("Surface timeout");
}
}
}
Err(err) => {
log::error!("{:?}", err);
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,

Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
}
}
Event::RedrawEventsCleared => {
Expand Down Expand Up @@ -186,6 +197,7 @@ fn make_sg(

SceneGraph {
groups: vec![SceneGroup {
name: "".to_string(),
bounds: GroupBounds {
x: 0.0,
y: 0.0,
Expand All @@ -210,6 +222,12 @@ fn make_sg(
gradients: vec![],
shape_index: EncodingValue::Scalar { value: 0 }
})],
gradients: vec![],
fill: None,
stroke: None,
stroke_width: None,
stroke_offset: None,
corner_radius: None,
}],
width,
height,
Expand Down
24 changes: 18 additions & 6 deletions examples/wgpu-winit/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use avenger::scene_graph::SceneGraph;
use avenger_vega::scene_graph::VegaSceneGraph;
use avenger_wgpu::canvas::{Canvas, CanvasDimensions, WindowCanvas};
use avenger_wgpu::error::AvengerWgpuError;
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use winit::window::WindowBuilder;
Expand Down Expand Up @@ -95,16 +96,27 @@ pub async fn run() {
}
Event::RedrawRequested(window_id) if window_id == canvas.window().id() => {
canvas.update();

match canvas.render() {
Ok(_) => {}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
canvas.resize(canvas.get_size())
Err(AvengerWgpuError::SurfaceError(err)) => {
match err {
wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated => {
canvas.resize(canvas.get_size());
}
wgpu::SurfaceError::OutOfMemory => {
// The system is out of memory, we should probably quit
*control_flow = ControlFlow::Exit;
}
wgpu::SurfaceError::Timeout => {
log::warn!("Surface timeout");
}
}
}
Err(err) => {
log::error!("{:?}", err);
}
// The system is out of memory, we should probably quit
Err(wgpu::SurfaceError::OutOfMemory) => *control_flow = ControlFlow::Exit,

Err(wgpu::SurfaceError::Timeout) => log::warn!("Surface timeout"),
}
}
Event::RedrawEventsCleared => {
Expand Down

0 comments on commit 4a82926

Please sign in to comment.