From 6e5b52e3bccb169e7ee63e23a94cc13f7d9dd037 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 17 May 2021 22:34:29 +0200 Subject: [PATCH] Add features extra_asserts and extra_debug_asserts for more asserts This replaces all debug_asserts with these opt-in asserts Related: https://github.com/emilk/egui/issues/395 --- CHANGELOG.md | 2 ++ egui/Cargo.toml | 10 ++++++++-- egui/src/containers/window.rs | 2 +- egui/src/frame_state.rs | 6 +++--- egui/src/layout.rs | 16 ++++++++-------- egui/src/lib.rs | 16 ++++++++++++++++ egui/src/placer.rs | 6 +++--- egui/src/response.rs | 4 ++-- egui/src/ui.rs | 4 ++-- egui/src/util/history.rs | 2 +- egui/src/widgets/slider.rs | 6 +++--- egui_demo_lib/Cargo.toml | 5 +++++ emath/Cargo.toml | 6 ++++++ emath/src/lib.rs | 26 +++++++++++++++++++++----- emath/src/rot2.rs | 2 +- emath/src/smart_aim.rs | 6 +++--- epaint/Cargo.toml | 13 ++++++++++--- epaint/src/color.rs | 10 +++++----- epaint/src/lib.rs | 16 ++++++++++++++++ epaint/src/mesh.rs | 10 +++++----- epaint/src/shape.rs | 2 +- epaint/src/tessellator.rs | 13 ++++++++----- epaint/src/text/font.rs | 2 +- epaint/src/text/galley.rs | 8 ++++---- 24 files changed, 135 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9b5db20..755878fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [ ## Unreleased +### Added ⭐ +* Add features `extra_asserts` and `extra_debug_asserts` to enable additional checks. ## 0.12.0 - 2021-05-10 - Multitouch, user memory, window pivots, and improved plots diff --git a/egui/Cargo.toml b/egui/Cargo.toml index ff3224fc..ee79b2eb 100644 --- a/egui/Cargo.toml +++ b/egui/Cargo.toml @@ -31,13 +31,19 @@ default = ["default_fonts", "single_threaded"] # If you plan on specifying your own fonts you may disable this feature. default_fonts = ["epaint/default_fonts"] +# Enable additional checks if debug assertions are enabled (debug builds). +extra_debug_asserts = ["epaint/extra_debug_asserts"] +# Always enable additional checks. +extra_asserts = ["epaint/extra_asserts"] + +# Add compatability with https://github.com/kvark/mint +mint = ["epaint/mint"] + persistence = ["serde", "epaint/persistence", "ron"] # Only needed if you plan to use the same egui::Context from multiple threads. single_threaded = ["epaint/single_threaded"] multi_threaded = ["epaint/multi_threaded"] -mint = ["epaint/mint"] - [dev-dependencies] serde_json = "1" diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 420b8cd5..1da3d554 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -212,7 +212,7 @@ impl<'open> Window<'open> { if self.scroll.is_none() { self.scroll = Some(ScrollArea::auto_sized()); } - debug_assert!( + crate::egui_assert!( self.scroll.is_some(), "Window::scroll called multiple times" ); diff --git a/egui/src/frame_state.rs b/egui/src/frame_state.rs index 84c4bf52..337ac979 100644 --- a/egui/src/frame_state.rs +++ b/egui/src/frame_state.rs @@ -70,7 +70,7 @@ impl FrameState { /// This is the "background" area, what egui doesn't cover with panels (but may cover with windows). /// This is also the area to which windows are constrained. pub(crate) fn available_rect(&self) -> Rect { - debug_assert!( + crate::egui_assert!( self.available_rect.is_finite(), "Called `available_rect()` before `CtxRef::begin_frame()`" ); @@ -79,7 +79,7 @@ impl FrameState { /// Shrink `available_rect`. pub(crate) fn allocate_left_panel(&mut self, panel_rect: Rect) { - debug_assert!( + crate::egui_assert!( panel_rect.min.distance(self.available_rect.min) < 0.1, "Mismatching left panel. You must not create a panel from within another panel." ); @@ -90,7 +90,7 @@ impl FrameState { /// Shrink `available_rect`. pub(crate) fn allocate_top_panel(&mut self, panel_rect: Rect) { - debug_assert!( + crate::egui_assert!( panel_rect.min.distance(self.available_rect.min) < 0.1, "Mismatching top panel. You must not create a panel from within another panel." ); diff --git a/egui/src/layout.rs b/egui/src/layout.rs index a9c5206a..c1508a29 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -342,8 +342,8 @@ impl Layout { /// ## Doing layout impl Layout { pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect { - debug_assert!(size.x >= 0.0 && size.y >= 0.0); - debug_assert!(!outer.is_negative()); + crate::egui_assert!(size.x >= 0.0 && size.y >= 0.0); + crate::egui_assert!(!outer.is_negative()); self.align2().align_size_within_rect(size, outer) } @@ -369,7 +369,7 @@ impl Layout { } pub(crate) fn region_from_max_rect(&self, max_rect: Rect) -> Region { - debug_assert!(!max_rect.any_nan()); + crate::egui_assert!(!max_rect.any_nan()); let mut region = Region { min_rect: Rect::NOTHING, // temporary max_rect, @@ -464,7 +464,7 @@ impl Layout { /// This is what you then pass to `advance_after_rects`. /// Use `justify_and_align` to get the inner `widget_rect`. pub(crate) fn next_frame(&self, region: &Region, child_size: Vec2, spacing: Vec2) -> Rect { - debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); + crate::egui_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); if self.main_wrap { let available_size = self.available_rect_before_wrap(region).size(); @@ -543,7 +543,7 @@ impl Layout { } fn next_frame_ignore_wrap(&self, region: &Region, child_size: Vec2) -> Rect { - debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); + crate::egui_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); let available_rect = self.available_rect_before_wrap_finite(region); @@ -581,8 +581,8 @@ impl Layout { /// Apply justify (fill width/height) and/or alignment after calling `next_space`. pub(crate) fn justify_and_align(&self, frame: Rect, mut child_size: Vec2) -> Rect { - debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); - debug_assert!(!frame.is_negative()); + crate::egui_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); + crate::egui_assert!(!frame.is_negative()); if self.horizontal_justify() { child_size.x = child_size.x.at_least(frame.width()); // fill full width @@ -600,7 +600,7 @@ impl Layout { ) -> Rect { let frame = self.next_frame_ignore_wrap(region, size); let rect = self.align_size_within_rect(size, frame); - debug_assert!((rect.size() - size).length() < 1.0); + crate::egui_assert!((rect.size() - size).length() < 1.0); rect } diff --git a/egui/src/lib.rs b/egui/src/lib.rs index c21a3206..5a3a6e17 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -418,6 +418,22 @@ macro_rules! github_link_file { // ---------------------------------------------------------------------------- +/// An assert that is only active when `egui` is compiled with the `egui_assert` feature +/// or with the `debug_egui_assert` feature in debug builds. +#[macro_export] +macro_rules! egui_assert { + ($($arg:tt)*) => { + if cfg!(any( + feature = "extra_asserts", + all(feature = "extra_debug_asserts", debug_assertions), + )) { + assert!($($arg)*); + } + } +} + +// ---------------------------------------------------------------------------- + /// egui supports around 1216 emojis in total. /// Here are some of the most useful: /// ∞⊗⎗⎘⎙⏏⏴⏵⏶⏷ diff --git a/egui/src/placer.rs b/egui/src/placer.rs index cea1546c..16bb7f73 100644 --- a/egui/src/placer.rs +++ b/egui/src/placer.rs @@ -133,8 +133,8 @@ impl Placer { /// Apply justify or alignment after calling `next_space`. pub(crate) fn justify_and_align(&self, rect: Rect, child_size: Vec2) -> Rect { - debug_assert!(!rect.any_nan()); - debug_assert!(!child_size.any_nan()); + crate::egui_assert!(!rect.any_nan()); + crate::egui_assert!(!child_size.any_nan()); if let Some(grid) = &self.grid { grid.justify_and_align(rect, child_size) @@ -146,7 +146,7 @@ impl Placer { /// Advance the cursor by this many points. /// [`Self::min_rect`] will expand to contain the cursor. pub(crate) fn advance_cursor(&mut self, amount: f32) { - debug_assert!( + crate::egui_assert!( self.grid.is_none(), "You cannot advance the cursor when in a grid layout" ); diff --git a/egui/src/response.rs b/egui/src/response.rs index dce7fd70..71b2ddd5 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -442,8 +442,8 @@ impl Response { /// For instance `a.union(b).hovered` means "was either a or b hovered?". pub fn union(&self, other: Self) -> Self { assert!(self.ctx == other.ctx); - debug_assert_eq!( - self.layer_id, other.layer_id, + crate::egui_assert!( + self.layer_id == other.layer_id, "It makes no sense to combine Responses from two different layers" ); Self { diff --git a/egui/src/ui.rs b/egui/src/ui.rs index dde3d511..ab8fab2c 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -78,7 +78,7 @@ impl Ui { /// Create a new `Ui` at a specific region. pub fn child_ui(&mut self, max_rect: Rect, layout: Layout) -> Self { - debug_assert!(!max_rect.any_nan()); + crate::egui_assert!(!max_rect.any_nan()); let next_auto_id_source = Id::new(self.next_auto_id_source).with("child").value(); self.next_auto_id_source = self.next_auto_id_source.wrapping_add(1); @@ -723,7 +723,7 @@ impl Ui { layout: Layout, add_contents: Box R + 'c>, ) -> InnerResponse { - debug_assert!(desired_size.x >= 0.0 && desired_size.y >= 0.0); + crate::egui_assert!(desired_size.x >= 0.0 && desired_size.y >= 0.0); let item_spacing = self.spacing().item_spacing; let frame_rect = self.placer.next_space(desired_size, item_spacing); let child_rect = self.placer.justify_and_align(frame_rect, desired_size); diff --git a/egui/src/util/history.rs b/egui/src/util/history.rs index fdefab63..ea91392d 100644 --- a/egui/src/util/history.rs +++ b/egui/src/util/history.rs @@ -104,7 +104,7 @@ where /// Values must be added with a monotonically increasing time, or at least not decreasing. pub fn add(&mut self, now: f64, value: T) { if let Some((last_time, _)) = self.values.back() { - debug_assert!(now >= *last_time, "Time shouldn't move backwards"); + crate::egui_assert!(now >= *last_time, "Time shouldn't move backwards"); } self.total_count += 1; self.values.push_back((now, value)); diff --git a/egui/src/widgets/slider.rs b/egui/src/widgets/slider.rs index f24c216d..cdb24b3e 100644 --- a/egui/src/widgets/slider.rs +++ b/egui/src/widgets/slider.rs @@ -523,7 +523,7 @@ fn value_from_normalized(normalized: f64, range: RangeInclusive, spec: &Sli } } } else { - debug_assert!( + crate::egui_assert!( min.is_finite() && max.is_finite(), "You should use a logarithmic range" ); @@ -572,7 +572,7 @@ fn normalized_from_value(value: f64, range: RangeInclusive, spec: &SliderSp } } } else { - debug_assert!( + crate::egui_assert!( min.is_finite() && max.is_finite(), "You should use a logarithmic range" ); @@ -620,6 +620,6 @@ fn logaritmic_zero_cutoff(min: f64, max: f64) -> f64 { }; let cutoff = min_magnitude / (min_magnitude + max_magnitude); - debug_assert!(0.0 <= cutoff && cutoff <= 1.0); + crate::egui_assert!(0.0 <= cutoff && cutoff <= 1.0); cutoff } diff --git a/egui_demo_lib/Cargo.toml b/egui_demo_lib/Cargo.toml index 1b38c444..7ae13163 100644 --- a/egui_demo_lib/Cargo.toml +++ b/egui_demo_lib/Cargo.toml @@ -44,6 +44,11 @@ http = ["image", "epi/http"] persistence = ["egui/persistence", "epi/persistence", "serde"] syntax_highlighting = ["syntect"] +# Enable additional checks if debug assertions are enabled (debug builds). +extra_debug_asserts = ["egui/extra_debug_asserts"] +# Always enable additional checks. +extra_asserts = ["egui/extra_asserts"] + [[bench]] name = "benchmark" harness = false diff --git a/emath/Cargo.toml b/emath/Cargo.toml index 667f033e..c396bdc8 100644 --- a/emath/Cargo.toml +++ b/emath/Cargo.toml @@ -20,8 +20,14 @@ include = [ [lib] [dependencies] +# Add compatability with https://github.com/kvark/mint mint = { version = "0.5.6", optional = true } serde = { version = "1", features = ["derive"], optional = true } [features] default = [] + +# Enable additional checks if debug assertions are enabled (debug builds). +extra_debug_asserts = [] +# Always enable additional checks. +extra_asserts = [] diff --git a/emath/src/lib.rs b/emath/src/lib.rs index 683c238a..f963fba3 100644 --- a/emath/src/lib.rs +++ b/emath/src/lib.rs @@ -163,7 +163,7 @@ pub fn remap(x: T, from: RangeInclusive, to: RangeInclusive) -> T where T: Real, { - debug_assert!(from.start() != from.end()); + crate::emath_assert!(from.start() != from.end()); let t = (x - *from.start()) / (*from.end() - *from.start()); lerp(to, t) } @@ -181,7 +181,7 @@ where } else if *from.end() <= x { *to.end() } else { - debug_assert!(from.start() != from.end()); + crate::emath_assert!(from.start() != from.end()); let t = (x - *from.start()) / (*from.end() - *from.start()); // Ensure no numerical inaccuracies sneak in: if T::one() <= t { @@ -200,7 +200,7 @@ pub fn clamp(x: T, range: RangeInclusive) -> T where T: Copy + PartialOrd, { - debug_assert!(range.start() <= range.end()); + crate::emath_assert!(range.start() <= range.end()); if x <= *range.start() { *range.start() } else if *range.end() <= x { @@ -225,8 +225,8 @@ pub fn format_with_minimum_decimals(value: f64, decimals: usize) -> String { pub fn format_with_decimals_in_range(value: f64, decimal_range: RangeInclusive) -> String { let min_decimals = *decimal_range.start(); let max_decimals = *decimal_range.end(); - debug_assert!(min_decimals <= max_decimals); - debug_assert!(max_decimals < 100); + crate::emath_assert!(min_decimals <= max_decimals); + crate::emath_assert!(max_decimals < 100); let max_decimals = max_decimals.min(16); let min_decimals = min_decimals.min(max_decimals); @@ -381,3 +381,19 @@ fn test_normalized_angle() { almost_eq!(normalized_angle(TAU), 0.0); almost_eq!(normalized_angle(2.7 * TAU), -0.3 * TAU); } + +// ---------------------------------------------------------------------------- + +/// An assert that is only active when `egui` is compiled with the `egui_assert` feature +/// or with the `debug_egui_assert` feature in debug builds. +#[macro_export] +macro_rules! emath_assert { + ($($arg:tt)*) => { + if cfg!(any( + feature = "extra_asserts", + all(feature = "extra_debug_asserts", debug_assertions), + )) { + assert!($($arg)*); + } + } +} diff --git a/emath/src/rot2.rs b/emath/src/rot2.rs index e274bd85..ffd851fd 100644 --- a/emath/src/rot2.rs +++ b/emath/src/rot2.rs @@ -76,7 +76,7 @@ impl Rot2 { c: self.c / l, s: self.s / l, }; - debug_assert!(ret.is_finite()); + crate::emath_assert!(ret.is_finite()); ret } } diff --git a/emath/src/smart_aim.rs b/emath/src/smart_aim.rs index c9b48d90..84823595 100644 --- a/emath/src/smart_aim.rs +++ b/emath/src/smart_aim.rs @@ -33,7 +33,7 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 { if !max.is_finite() { return min; } - debug_assert!(min.is_finite() && max.is_finite()); + crate::emath_assert!(min.is_finite() && max.is_finite()); let min_exponent = min.log10(); let max_exponent = max.log10(); @@ -82,7 +82,7 @@ fn is_integer(f: f64) -> bool { } fn to_decimal_string(v: f64) -> [i32; NUM_DECIMALS] { - debug_assert!(v < 10.0, "{:?}", v); + crate::emath_assert!(v < 10.0, "{:?}", v); let mut digits = [0; NUM_DECIMALS]; let mut v = v.abs(); for r in digits.iter_mut() { @@ -104,7 +104,7 @@ fn from_decimal_string(s: &[i32]) -> f64 { /// Find the simplest integer in the range [min, max] fn simplest_digit_closed_range(min: i32, max: i32) -> i32 { - debug_assert!(1 <= min && min <= max && max <= 9); + crate::emath_assert!(1 <= min && min <= max && max <= 9); if min <= 5 && 5 <= max { 5 } else { diff --git a/epaint/Cargo.toml b/epaint/Cargo.toml index b59729fb..2506984b 100644 --- a/epaint/Cargo.toml +++ b/epaint/Cargo.toml @@ -33,15 +33,22 @@ serde = { version = "1", features = ["derive"], optional = true } [features] default = ["multi_threaded", "default_fonts"] -persistence = ["serde", "emath/serde"] # If set, epaint will use `include_bytes!` to bundle some fonts. # If you plan on specifying your own fonts you may disable this feature. default_fonts = [] +# Enable additional checks if debug assertions are enabled (debug builds). +extra_debug_asserts = ["emath/extra_debug_asserts"] +# Always enable additional checks. +extra_asserts = ["emath/extra_asserts"] + +# Add compatability with https://github.com/kvark/mint +mint = ["emath/mint"] + +persistence = ["serde", "emath/serde"] + single_threaded = ["atomic_refcell"] # Only needed if you plan to use the same fonts from multiple threads. multi_threaded = ["parking_lot"] - -mint = ["emath/mint"] diff --git a/epaint/src/color.rs b/epaint/src/color.rs index 3ed144b1..3fd2fea6 100644 --- a/epaint/src/color.rs +++ b/epaint/src/color.rs @@ -160,7 +160,7 @@ impl Color32 { /// Multiply with 0.5 to make color half as opaque. pub fn linear_multiply(self, factor: f32) -> Color32 { - debug_assert!(0.0 <= factor && factor <= 1.0); + crate::epaint_assert!(0.0 <= factor && factor <= 1.0); // As an unfortunate side-effect of using premultiplied alpha // we need a somewhat expensive conversion to linear space and back. Rgba::from(self).multiply(factor).into() @@ -214,22 +214,22 @@ impl Rgba { } pub fn from_luminance_alpha(l: f32, a: f32) -> Self { - debug_assert!(0.0 <= l && l <= 1.0); - debug_assert!(0.0 <= a && a <= 1.0); + crate::epaint_assert!(0.0 <= l && l <= 1.0); + crate::epaint_assert!(0.0 <= a && a <= 1.0); Self([l * a, l * a, l * a, a]) } /// Transparent black #[inline(always)] pub fn from_black_alpha(a: f32) -> Self { - debug_assert!(0.0 <= a && a <= 1.0); + crate::epaint_assert!(0.0 <= a && a <= 1.0); Self([0.0, 0.0, 0.0, a]) } /// Transparent white #[inline(always)] pub fn from_white_alpha(a: f32) -> Self { - debug_assert!(0.0 <= a && a <= 1.0); + crate::epaint_assert!(0.0 <= a && a <= 1.0); Self([a, a, a, a]) } diff --git a/epaint/src/lib.rs b/epaint/src/lib.rs index 5d80b8fa..445a2584 100644 --- a/epaint/src/lib.rs +++ b/epaint/src/lib.rs @@ -159,3 +159,19 @@ pub struct ClippedMesh( /// The shape pub Mesh, ); + +// ---------------------------------------------------------------------------- + +/// An assert that is only active when `egui` is compiled with the `egui_assert` feature +/// or with the `debug_egui_assert` feature in debug builds. +#[macro_export] +macro_rules! epaint_assert { + ($($arg:tt)*) => { + if cfg!(any( + feature = "extra_asserts", + all(feature = "extra_debug_asserts", debug_assertions), + )) { + assert!($($arg)*); + } + } +} diff --git a/epaint/src/mesh.rs b/epaint/src/mesh.rs index 9c273ac6..771f9917 100644 --- a/epaint/src/mesh.rs +++ b/epaint/src/mesh.rs @@ -74,7 +74,7 @@ impl Mesh { /// Append all the indices and vertices of `other` to `self`. pub fn append(&mut self, other: Mesh) { - debug_assert!(other.is_valid()); + crate::epaint_assert!(other.is_valid()); if self.is_empty() { *self = other; @@ -94,7 +94,7 @@ impl Mesh { #[inline(always)] pub fn colored_vertex(&mut self, pos: Pos2, color: Color32) { - debug_assert!(self.texture_id == TextureId::Egui); + crate::epaint_assert!(self.texture_id == TextureId::Egui); self.vertices.push(Vertex { pos, uv: WHITE_UV, @@ -157,7 +157,7 @@ impl Mesh { /// Uniformly colored rectangle. #[inline(always)] pub fn add_colored_rect(&mut self, rect: Rect, color: Color32) { - debug_assert!(self.texture_id == TextureId::Egui); + crate::epaint_assert!(self.texture_id == TextureId::Egui); self.add_rect_with_uv(rect, [WHITE_UV, WHITE_UV].into(), color) } @@ -166,7 +166,7 @@ impl Mesh { /// Splits this mesh into many smaller meshes (if needed) /// where the smaller meshes have 16-bit indices. pub fn split_to_u16(self) -> Vec { - debug_assert!(self.is_valid()); + crate::epaint_assert!(self.is_valid()); const MAX_SIZE: u32 = 1 << 16; @@ -220,7 +220,7 @@ impl Mesh { vertices: self.vertices[(min_vindex as usize)..=(max_vindex as usize)].to_vec(), texture_id: self.texture_id, }; - debug_assert!(mesh.is_valid()); + crate::epaint_assert!(mesh.is_valid()); output.push(mesh); } output diff --git a/epaint/src/shape.rs b/epaint/src/shape.rs index 93e6ad2d..d9bd2bdc 100644 --- a/epaint/src/shape.rs +++ b/epaint/src/shape.rs @@ -147,7 +147,7 @@ impl Shape { /// ## Operations impl Shape { pub fn mesh(mesh: Mesh) -> Self { - debug_assert!(mesh.is_valid()); + crate::epaint_assert!(mesh.is_valid()); Self::Mesh(mesh) } diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index 304b1009..efae55d5 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -456,7 +456,7 @@ fn stroke_path( } fn mul_color(color: Color32, factor: f32) -> Color32 { - debug_assert!(0.0 <= factor && factor <= 1.0); + crate::epaint_assert!(0.0 <= factor && factor <= 1.0); // As an unfortunate side-effect of using premultiplied alpha // we need a somewhat expensive conversion to linear space and back. color.linear_multiply(factor) @@ -528,7 +528,7 @@ impl Tessellator { if mesh.is_valid() { out.append(mesh); } else { - debug_assert!(false, "Invalid Mesh in Shape::Mesh"); + crate::epaint_assert!(false, "Invalid Mesh in Shape::Mesh"); } } Shape::LineSegment { points, stroke } => { @@ -553,7 +553,7 @@ impl Tessellator { } if fill != Color32::TRANSPARENT { - debug_assert!( + crate::epaint_assert!( closed, "You asked to fill a path that is not closed. That makes no sense." ); @@ -641,7 +641,10 @@ impl Tessellator { if color == Color32::TRANSPARENT || galley.is_empty() { return; } - if cfg!(debug_assertions) { + if cfg!(any( + feature = "extra_asserts", + all(feature = "extra_debug_asserts", debug_assertions), + )) { galley.sanity_check(); } @@ -790,7 +793,7 @@ pub fn tessellate_shapes( } for ClippedMesh(_, mesh) in &clipped_meshes { - debug_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh"); + crate::epaint_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh"); } clipped_meshes diff --git a/epaint/src/text/font.rs b/epaint/src/text/font.rs index c530df44..33c2b231 100644 --- a/epaint/src/text/font.rs +++ b/epaint/src/text/font.rs @@ -467,7 +467,7 @@ impl Font { let mut out_rows = vec![]; for (i, (x, chr)) in full_x_offsets.iter().skip(1).zip(text.chars()).enumerate() { - debug_assert!(chr != '\n'); + crate::epaint_assert!(chr != '\n'); let potential_row_width = first_row_indentation + x - row_start_x; if potential_row_width > max_width_in_points { diff --git a/epaint/src/text/galley.rs b/epaint/src/text/galley.rs index f901b912..7a6b32be 100644 --- a/epaint/src/text/galley.rs +++ b/epaint/src/text/galley.rs @@ -158,9 +158,9 @@ impl Galley { row.sanity_check(); char_count += row.char_count_including_newline(); } - debug_assert_eq!(char_count, self.text.chars().count()); + crate::epaint_assert!(char_count == self.text.chars().count()); if let Some(last_row) = self.rows.last() { - debug_assert!( + crate::epaint_assert!( !last_row.ends_with_newline, "If the text ends with '\\n', there would be an empty row last.\n\ Galley: {:#?}", @@ -304,7 +304,7 @@ impl Galley { pub fn end_rcursor(&self) -> RCursor { if let Some(last_row) = self.rows.last() { - debug_assert!(!last_row.ends_with_newline); + crate::epaint_assert!(!last_row.ends_with_newline); RCursor { row: self.rows.len() - 1, column: last_row.char_count_excluding_newline(), @@ -361,7 +361,7 @@ impl Galley { pcursor_it.offset += row.char_count_including_newline(); } } - debug_assert_eq!(ccursor_it, self.end().ccursor); + crate::epaint_assert!(ccursor_it == self.end().ccursor); Cursor { ccursor: ccursor_it, // clamp rcursor: self.end_rcursor(),