Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer overflow with nested clip primitives #43

Merged
merged 2 commits into from
Nov 7, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions wgpu/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@memoryruins memoryruins Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is theTODO referring to a parent layer that is already defined/accessible?
or are parents part of #30 to be implemented?

Copy link
Member Author

@hecrj hecrj Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the parent layer should be the layer variable.

Implementing this TODO should be a simple rectangle intersection check. In fact, I think this is implementable for all primitives.

I have not decided to go for it yet because performance is not my main concern at this point. I prefer to keep code manageable and simple for now, while we are figuring things out.

// 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);
}
}
}
}
Expand Down