Skip to content

Commit

Permalink
Merge pull request #230 from spamviech/fix-no-wgpu-segfault
Browse files Browse the repository at this point in the history
Hide fill_quad behind intersects/>0-checks to avoid triggering debug_assert in the tiny_skia-renderer
  • Loading branch information
genusistimelord authored Apr 8, 2024
2 parents ca40220 + 2990380 commit bb7540f
Show file tree
Hide file tree
Showing 31 changed files with 722 additions and 645 deletions.
4 changes: 1 addition & 3 deletions examples/WidgetIDReturn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ iced_aw = { workspace = true, features = [
"number_input",
"icons",
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
num-traits = "0.2.16"
4 changes: 1 addition & 3 deletions examples/badge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ iced_aw = { workspace = true, features = [
"icons",
] }

iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
5 changes: 2 additions & 3 deletions examples/card/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ edition = "2021"
iced_aw = { workspace = true, features = [
"card", "icons"
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true

5 changes: 2 additions & 3 deletions examples/color_picker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ edition = "2021"
iced_aw = { workspace = true, features = [
"color_picker",
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true

4 changes: 1 addition & 3 deletions examples/drop_down/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ iced_aw = { workspace = true, features = [
"drop_down",
"icons",
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
4 changes: 1 addition & 3 deletions examples/floating_element multioverlay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ iced_aw = { workspace = true, features = [
"floating_element",
"icons",
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
4 changes: 1 addition & 3 deletions examples/font_loading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
iced_aw = { workspace = true, features = [ "icons" ] }

2 changes: 1 addition & 1 deletion examples/menu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ iced_aw = { workspace = true, features = [
"quad",
"icons"
] }
iced = {workspace = true, features = ["svg", "wgpu"]}
iced = {workspace = true, features = ["svg"]}
4 changes: 1 addition & 3 deletions examples/multiple_modals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ edition = "2021"

[dependencies]
iced_aw = { workspace = true, features = ["card", "modal", "icons"] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace = true
2 changes: 1 addition & 1 deletion examples/multiple_modals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> iced::Result {
window: window::Settings {
size: iced::Size {
width: 500.0,
height: 150.0,
height: 175.0,
},
position: window::Position::Centered,
..Default::default()
Expand Down
4 changes: 1 addition & 3 deletions examples/number_input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ iced_aw = { workspace = true, features = [
"icons",
] }

iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true
5 changes: 2 additions & 3 deletions examples/sliderbar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ iced_aw = { workspace = true, features = [
"icons",
"number_input",
] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace=true

4 changes: 1 addition & 3 deletions examples/tab_bar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ edition = "2021"

[dependencies]
iced_aw = { workspace = true, features = ["tab_bar", "icons"] }
iced = { workspace = true, features = [
"wgpu",
] }
iced.workspace = true
24 changes: 13 additions & 11 deletions src/widgets/badge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,20 @@ where
.border_radius
.unwrap_or(bounds.height / BORDER_RADIUS_RATIO);

renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color.unwrap_or(Color::BLACK),
if bounds.intersects(viewport) {
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color.unwrap_or(Color::BLACK),
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.background,
);
style_sheet.background,
);
}

self.content.as_widget().draw(
&tree.children[0],
Expand Down
163 changes: 88 additions & 75 deletions src/widgets/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,34 +502,36 @@ where
let mut children = layout.children();
let style_sheet = theme.active(&self.style);

// Background
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: style_sheet.border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color,
if bounds.intersects(viewport) {
// Background
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: style_sheet.border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.background,
);

// Border
renderer.fill_quad(
// TODO: fill not necessary
renderer::Quad {
bounds,
border: Border {
radius: style_sheet.border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color,
style_sheet.background,
);

// Border
renderer.fill_quad(
// TODO: fill not necessary
renderer::Quad {
bounds,
border: Border {
radius: style_sheet.border_radius.into(),
width: style_sheet.border_width,
color: style_sheet.border_color,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
Color::TRANSPARENT,
);
Color::TRANSPARENT,
);
}

// ----------- Head ----------------------
let head_layout = children
Expand Down Expand Up @@ -758,37 +760,42 @@ fn draw_head<Message, Theme, Renderer>(
let border_radius = style_sheet.border_radius;

// Head background
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: border_radius.into(),
width: 0.0,
color: Color::TRANSPARENT,
if bounds.intersects(viewport) {
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: border_radius.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.head_background,
);
style_sheet.head_background,
);
}

// cover rounded button of header
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
x: bounds.x,
y: bounds.y + bounds.height - border_radius,
width: bounds.width,
height: border_radius,
},
border: Border {
radius: (0.0).into(),
width: 0.0,
color: Color::TRANSPARENT,
let button_bounds = Rectangle {
x: bounds.x,
y: bounds.y + bounds.height - border_radius,
width: bounds.width,
height: border_radius,
};
if button_bounds.intersects(viewport) {
renderer.fill_quad(
renderer::Quad {
bounds: button_bounds,
border: Border {
radius: (0.0).into(),
width: 0.0,
color: Color::TRANSPARENT,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.head_background,
);
style_sheet.head_background,
);
}

head.as_widget().draw(
state,
Expand Down Expand Up @@ -846,20 +853,23 @@ fn draw_body<Message, Theme, Renderer>(
{
let mut body_children = layout.children();
let style_sheet = theme.active(style);
let bounds = layout.bounds();

// Body background
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border: Border {
radius: (0.0).into(),
width: 0.0,
color: Color::TRANSPARENT,
if bounds.intersects(viewport) {
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: (0.0).into(),
width: 0.0,
color: Color::TRANSPARENT,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.body_background,
);
style_sheet.body_background,
);
}

body.as_widget().draw(
state,
Expand Down Expand Up @@ -893,20 +903,23 @@ fn draw_foot<Message, Theme, Renderer>(
{
let mut foot_children = layout.children();
let style_sheet = theme.active(style);
let bounds = layout.bounds();

// Foot background
renderer.fill_quad(
renderer::Quad {
bounds: layout.bounds(),
border: Border {
radius: style_sheet.border_radius.into(),
width: 0.0,
color: Color::TRANSPARENT,
if bounds.intersects(viewport) {
renderer.fill_quad(
renderer::Quad {
bounds,
border: Border {
radius: style_sheet.border_radius.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
shadow: Shadow::default(),
},
shadow: Shadow::default(),
},
style_sheet.foot_background,
);
style_sheet.foot_background,
);
}

if let Some((foot, state)) = foot.as_ref().zip(state) {
foot.as_widget().draw(
Expand Down
Loading

0 comments on commit bb7540f

Please sign in to comment.