Skip to content

Commit

Permalink
Fix panic in winit examples when pixels.render() returns Error (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
parasyte authored Apr 14, 2020
1 parent d88b452 commit 91db963
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 9 additions & 2 deletions examples/conway/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(clippy::all)]
#![forbid(unsafe_code)]

use log::debug;
use log::{debug, error};
use pixels::{Error, Pixels, SurfaceTexture};
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
use winit::event::{Event, VirtualKeyCode};
Expand Down Expand Up @@ -30,7 +30,14 @@ fn main() -> Result<(), Error> {
// The one and only event that winit_input_helper doesn't have for us...
if let Event::RedrawRequested(_) = event {
life.draw(pixels.get_frame());
pixels.render().unwrap();
if pixels
.render()
.map_err(|e| error!("pixels.render() failed: {}", e))
.is_err()
{
*control_flow = ControlFlow::Exit;
return;
}
}

// For everything else, for let winit_input_helper collect events to build its state.
Expand Down
11 changes: 9 additions & 2 deletions examples/invaders/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
use std::time::Instant;

use gilrs::{Button, Gilrs};
use log::debug;
use log::{debug, error};
use pixels::{Error, Pixels, SurfaceTexture};
use simple_invaders::{Controls, Direction, World, SCREEN_HEIGHT, SCREEN_WIDTH};
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
Expand Down Expand Up @@ -37,7 +37,14 @@ fn main() -> Result<(), Error> {
// The one and only event that winit_input_helper doesn't have for us...
if let Event::RedrawRequested(_) = event {
invaders.draw(pixels.get_frame());
pixels.render().unwrap();
if pixels
.render()
.map_err(|e| error!("pixels.render() failed: {}", e))
.is_err()
{
*control_flow = ControlFlow::Exit;
return;
}
}

// Pump the gilrs event loop and find an active gamepad
Expand Down
10 changes: 9 additions & 1 deletion examples/minimal-winit/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::all)]
#![forbid(unsafe_code)]

use log::error;
use pixels::{wgpu::Surface, Error, Pixels, SurfaceTexture};
use winit::dpi::LogicalSize;
use winit::event::{Event, VirtualKeyCode};
Expand Down Expand Up @@ -46,7 +47,14 @@ fn main() -> Result<(), Error> {
// Draw the current frame
if let Event::RedrawRequested(_) = event {
world.draw(pixels.get_frame());
pixels.render().unwrap();
if pixels
.render()
.map_err(|e| error!("pixels.render() failed: {}", e))
.is_err()
{
*control_flow = ControlFlow::Exit;
return;
}
}

// Handle input events
Expand Down

0 comments on commit 91db963

Please sign in to comment.