summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-06 21:00:24 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-06 21:34:57 +0100
commit8074bca8a083c5ecfed941b112ec60dca6ae2deb (patch)
tree72159fa84e9e1ab0634d1feb5a46943abdeca292 /wgpu
parentefa8d267b8e1d667902b1e0d0e7c6e4d79e75f6e (diff)
downloadiced-8074bca8a083c5ecfed941b112ec60dca6ae2deb.tar.gz
iced-8074bca8a083c5ecfed941b112ec60dca6ae2deb.tar.bz2
iced-8074bca8a083c5ecfed941b112ec60dca6ae2deb.zip
Fix integer overflow with nested clip primitives
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/renderer.rs43
1 files changed, 25 insertions, 18 deletions
diff --git a/wgpu/src/renderer.rs b/wgpu/src/renderer.rs
index f46acb8c..1d40c215 100644
--- a/wgpu/src/renderer.rs
+++ b/wgpu/src/renderer.rs
@@ -254,24 +254,31 @@ 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 - layer.offset.x as f32;
+ let y = bounds.y - layer.offset.y as f32;
+ let width = (bounds.width + x).min(bounds.width);
+ let height = (bounds.height + y).min(bounds.height);
+
+ // Only draw visible content on-screen
+ // TODO: Also, check for parent layer bounds to avoid further
+ // drawing in some circumstances.
+ if width > 0.0 && height > 0.0 {
+ let clip_layer = Layer::new(
+ Rectangle {
+ x: x.max(0.0).ceil() as u32,
+ y: y.max(0.0).ceil() as u32,
+ width: width.ceil() as u32,
+ height: height.ceil() 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);
+ }
}
}
}