From 0f1df90d904925e7808b3e4c28ea0bdad6c3ed4c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 19 Apr 2021 23:00:20 +0200 Subject: [PATCH] Tesselator: ignore non-positive clip rectangles Closes https://github.com/emilk/egui/issues/328 --- emath/src/rect.rs | 3 +++ epaint/src/tessellator.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/emath/src/rect.rs b/emath/src/rect.rs index 3584a1859..7875cd5ca 100644 --- a/emath/src/rect.rs +++ b/emath/src/rect.rs @@ -304,16 +304,19 @@ impl Rect { } /// `min.x <= max.x && min.y <= max.y`. + #[inline(always)] pub fn is_non_negative(&self) -> bool { self.min.x <= self.max.x && self.min.y <= self.max.y } /// True if all members are also finite. + #[inline(always)] pub fn is_finite(&self) -> bool { self.min.is_finite() && self.max.is_finite() } /// True if any member is NaN. + #[inline(always)] pub fn any_nan(self) -> bool { self.min.any_nan() || self.max.any_nan() } diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index f560ec6df..135e219f3 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -742,6 +742,10 @@ pub fn tessellate_shapes( let mut clipped_meshes: Vec = Vec::default(); for ClippedShape(clip_rect, shape) in shapes { + if !clip_rect.is_non_negative() { + continue; // skip empty clip rectangles + } + let start_new_mesh = match clipped_meshes.last() { None => true, Some(cm) => cm.0 != clip_rect || cm.1.texture_id != shape.texture_id(),