Merge pull request #602 from zed-industries/fix-atlas-panic

Don't draw scene elements if their size is zero
This commit is contained in:
Antonio Scandurra 2022-03-14 15:38:42 +01:00 committed by GitHub
commit e62781a57b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -279,32 +279,40 @@ impl Layer {
} }
fn push_quad(&mut self, quad: Quad) { fn push_quad(&mut self, quad: Quad) {
if can_draw(quad.bounds) {
self.quads.push(quad); self.quads.push(quad);
} }
}
pub fn quads(&self) -> &[Quad] { pub fn quads(&self) -> &[Quad] {
self.quads.as_slice() self.quads.as_slice()
} }
fn push_underline(&mut self, underline: Underline) { fn push_underline(&mut self, underline: Underline) {
if underline.width > 0. {
self.underlines.push(underline); self.underlines.push(underline);
} }
}
pub fn underlines(&self) -> &[Underline] { pub fn underlines(&self) -> &[Underline] {
self.underlines.as_slice() self.underlines.as_slice()
} }
fn push_image(&mut self, image: Image) { fn push_image(&mut self, image: Image) {
if can_draw(image.bounds) {
self.images.push(image); self.images.push(image);
} }
}
pub fn images(&self) -> &[Image] { pub fn images(&self) -> &[Image] {
self.images.as_slice() self.images.as_slice()
} }
fn push_shadow(&mut self, shadow: Shadow) { fn push_shadow(&mut self, shadow: Shadow) {
if can_draw(shadow.bounds) {
self.shadows.push(shadow); self.shadows.push(shadow);
} }
}
pub fn shadows(&self) -> &[Shadow] { pub fn shadows(&self) -> &[Shadow] {
self.shadows.as_slice() self.shadows.as_slice()
@ -319,15 +327,17 @@ impl Layer {
} }
pub fn push_icon(&mut self, icon: Icon) { pub fn push_icon(&mut self, icon: Icon) {
if can_draw(icon.bounds) {
self.icons.push(icon); self.icons.push(icon);
} }
}
pub fn icons(&self) -> &[Icon] { pub fn icons(&self) -> &[Icon] {
self.icons.as_slice() self.icons.as_slice()
} }
fn push_path(&mut self, path: Path) { fn push_path(&mut self, path: Path) {
if !path.bounds.is_empty() { if can_draw(path.bounds) {
self.paths.push(path); self.paths.push(path);
} }
} }
@ -429,3 +439,8 @@ impl ToJson for Border {
value value
} }
} }
fn can_draw(bounds: RectF) -> bool {
let size = bounds.size();
size.x() > 0. && size.y() > 0.
}