Skip to content

Commit

Permalink
Validate that a framebuffer isn't 0 on any dimension
Browse files Browse the repository at this point in the history
This would lead to other errors down the line, also fixed the
fxaa example, since when minimizing/resizing on Windows the framebuffer
could become 0 on one dimension.
  • Loading branch information
Melchizedek6809 committed Apr 1, 2023
1 parent db6fcd3 commit ca8f54b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/fxaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,15 @@ mod fxaa {
pub fn draw<T, F, R>(system: &FxaaSystem, target: &mut T, enabled: bool, mut draw: F)
-> R where T: Surface, F: FnMut(&mut SimpleFrameBuffer<'_>) -> R
{
let target_dimensions = target.get_dimensions();
let mut target_dimensions = target.get_dimensions();
// We need to ensure that our framebuffer is at least 1x1. Otherwise, we would get an error.
// This could happen when minimizing or resizing the window on Windows, for example.
if target_dimensions.0 == 0 {
target_dimensions.0 = 1;
}
if target_dimensions.1 == 0 {
target_dimensions.1 = 1;
}

let mut target_color = system.target_color.borrow_mut();
let mut target_depth = system.target_depth.borrow_mut();
Expand Down
6 changes: 6 additions & 0 deletions src/fbo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ impl<'a> FramebufferAttachments<'a> {
}

let dimensions = if let Some(dimensions) = dimensions {
if dimensions.0 * dimensions.1 == 0 {
return Err(ValidationError::EmptyFramebufferUnsupportedDimensions);
}
dimensions
} else {
// TODO: handle this
Expand Down Expand Up @@ -517,6 +520,9 @@ impl<'a> FramebufferAttachments<'a> {
}

let dimensions = if let Some(dimensions) = dimensions {
if dimensions.0 * dimensions.1 == 0 {
return Err(ValidationError::EmptyFramebufferUnsupportedDimensions);
}
dimensions
} else {
// TODO: handle this
Expand Down

0 comments on commit ca8f54b

Please sign in to comment.