Skip to content

Commit

Permalink
Fix integer overflow with nested clip primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 6, 2019
1 parent efa8d26 commit af80006
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,32 @@ impl Renderer {
offset,
content,
} => {
let clip_layer = Layer::new(
Rectangle {
x: bounds.x as u32 - layer.offset.x,
y: bounds.y as u32 - layer.offset.y,
width: bounds.width as u32,
height: bounds.height as u32,
},
layer.offset + *offset,
);

let new_layer = Layer::new(layer.bounds, layer.offset);

layers.push(clip_layer);

// TODO: Primitive culling
self.draw_primitive(content, layers);

layers.push(new_layer);
let x = bounds.x as i32 - layer.offset.x as i32;
let y = bounds.y as i32 - layer.offset.y as i32;
let width = (bounds.width as i32 + x).min(bounds.width as i32);
let height =
(bounds.height as i32 + y).min(bounds.height as i32);

// Only draw visible content on-screen
// TODO: Also, check for parent layer bounds to avoid further
// drawing in some circumstances.
if width > 0 && height > 0 {
let clip_layer = Layer::new(
Rectangle {
x: x.max(0) as u32,
y: y.max(0) as u32,
width: width as u32,
height: height as u32,
},
layer.offset + *offset,
);

let new_layer = Layer::new(layer.bounds, layer.offset);

layers.push(clip_layer);
self.draw_primitive(content, layers);
layers.push(new_layer);
}
}
}
}
Expand Down

0 comments on commit af80006

Please sign in to comment.