mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
Remove extra_asserts and extra_debug_asserts feature flags (#4478)
Removes `egui_assert` etc and replaces it with normal `debug_assert` calls. Previously you could opt-in to more runtime checks using feature flags. Now these extra runtime checks are always enabled for debug builds. You are most likely to encounter them if you use negative sizes or NaNs or other similar bugs. These usually indicate bugs in user space.
This commit is contained in:
@@ -52,14 +52,6 @@ deadlock_detection = ["dep:backtrace"]
|
||||
## 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",
|
||||
"ecolor/extra_debug_asserts",
|
||||
]
|
||||
## Always enable additional checks.
|
||||
extra_asserts = ["emath/extra_asserts", "ecolor/extra_asserts"]
|
||||
|
||||
## Turn on the `log` feature, that makes egui log some errors using the [`log`](https://docs.rs/log) crate.
|
||||
log = ["dep:log"]
|
||||
|
||||
|
||||
@@ -141,8 +141,8 @@ impl CubicBezierShape {
|
||||
|
||||
/// split the original cubic curve into a new one within a range.
|
||||
pub fn split_range(&self, t_range: Range<f32>) -> Self {
|
||||
crate::epaint_assert!(
|
||||
t_range.start >= 0.0 && t_range.end <= 1.0 && t_range.start <= t_range.end,
|
||||
debug_assert!(
|
||||
0.0 <= t_range.start && t_range.end <= 1.0 && t_range.start <= t_range.end,
|
||||
"range should be in [0.0,1.0]"
|
||||
);
|
||||
|
||||
@@ -178,7 +178,7 @@ impl CubicBezierShape {
|
||||
// https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=1000&context=facpub#section.10.6
|
||||
// and the error metric from the caffein owl blog post http://caffeineowl.com/graphics/2d/vectorial/cubic2quad01.html
|
||||
pub fn num_quadratics(&self, tolerance: f32) -> u32 {
|
||||
crate::epaint_assert!(tolerance > 0.0, "the tolerance should be positive");
|
||||
debug_assert!(tolerance > 0.0, "the tolerance should be positive");
|
||||
|
||||
let x =
|
||||
self.points[0].x - 3.0 * self.points[1].x + 3.0 * self.points[2].x - self.points[3].x;
|
||||
@@ -273,7 +273,7 @@ impl CubicBezierShape {
|
||||
/// [Bézier Curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves)
|
||||
///
|
||||
pub fn sample(&self, t: f32) -> Pos2 {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
t >= 0.0 && t <= 1.0,
|
||||
"the sample value should be in [0.0,1.0]"
|
||||
);
|
||||
@@ -496,7 +496,7 @@ impl QuadraticBezierShape {
|
||||
/// [Bézier Curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B.C3.A9zier_curves)
|
||||
///
|
||||
pub fn sample(&self, t: f32) -> Pos2 {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
t >= 0.0 && t <= 1.0,
|
||||
"the sample value should be in [0.0,1.0]"
|
||||
);
|
||||
|
||||
@@ -138,22 +138,6 @@ pub enum Primitive {
|
||||
Callback(PaintCallback),
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// An assert that is only active when `epaint` is compiled with the `extra_asserts` feature
|
||||
/// or with the `extra_debug_asserts` 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)*);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Was epaint compiled with the `rayon` feature?
|
||||
|
||||
@@ -109,7 +109,7 @@ impl Mesh {
|
||||
/// Append all the indices and vertices of `other` to `self`.
|
||||
pub fn append(&mut self, other: Self) {
|
||||
crate::profile_function!();
|
||||
crate::epaint_assert!(other.is_valid());
|
||||
debug_assert!(other.is_valid());
|
||||
|
||||
if self.is_empty() {
|
||||
*self = other;
|
||||
@@ -121,7 +121,7 @@ impl Mesh {
|
||||
/// Append all the indices and vertices of `other` to `self` without
|
||||
/// taking ownership.
|
||||
pub fn append_ref(&mut self, other: &Self) {
|
||||
crate::epaint_assert!(other.is_valid());
|
||||
debug_assert!(other.is_valid());
|
||||
|
||||
if self.is_empty() {
|
||||
self.texture_id = other.texture_id;
|
||||
@@ -140,7 +140,7 @@ impl Mesh {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn colored_vertex(&mut self, pos: Pos2, color: Color32) {
|
||||
crate::epaint_assert!(self.texture_id == TextureId::default());
|
||||
debug_assert!(self.texture_id == TextureId::default());
|
||||
self.vertices.push(Vertex {
|
||||
pos,
|
||||
uv: WHITE_UV,
|
||||
@@ -203,7 +203,7 @@ impl Mesh {
|
||||
/// Uniformly colored rectangle.
|
||||
#[inline(always)]
|
||||
pub fn add_colored_rect(&mut self, rect: Rect, color: Color32) {
|
||||
crate::epaint_assert!(self.texture_id == TextureId::default());
|
||||
debug_assert!(self.texture_id == TextureId::default());
|
||||
self.add_rect_with_uv(rect, [WHITE_UV, WHITE_UV].into(), color);
|
||||
}
|
||||
|
||||
@@ -212,7 +212,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<Mesh16> {
|
||||
crate::epaint_assert!(self.is_valid());
|
||||
debug_assert!(self.is_valid());
|
||||
|
||||
const MAX_SIZE: u32 = std::u16::MAX as u32;
|
||||
|
||||
@@ -265,7 +265,7 @@ impl Mesh {
|
||||
vertices: self.vertices[(min_vindex as usize)..=(max_vindex as usize)].to_vec(),
|
||||
texture_id: self.texture_id,
|
||||
};
|
||||
crate::epaint_assert!(mesh.is_valid());
|
||||
debug_assert!(mesh.is_valid());
|
||||
output.push(mesh);
|
||||
}
|
||||
output
|
||||
|
||||
@@ -313,7 +313,7 @@ impl Shape {
|
||||
|
||||
#[inline]
|
||||
pub fn mesh(mesh: Mesh) -> Self {
|
||||
crate::epaint_assert!(mesh.is_valid());
|
||||
debug_assert!(mesh.is_valid());
|
||||
Self::Mesh(mesh)
|
||||
}
|
||||
|
||||
|
||||
@@ -1311,7 +1311,7 @@ impl Tessellator {
|
||||
crate::profile_scope!("mesh");
|
||||
|
||||
if self.options.validate_meshes && !mesh.is_valid() {
|
||||
crate::epaint_assert!(false, "Invalid Mesh in Shape::Mesh");
|
||||
debug_assert!(false, "Invalid Mesh in Shape::Mesh");
|
||||
return;
|
||||
}
|
||||
// note: `append` still checks if the mesh is valid if extra asserts are enabled.
|
||||
@@ -1480,7 +1480,7 @@ impl Tessellator {
|
||||
/// * `out`: triangles are appended to this.
|
||||
pub fn tessellate_mesh(&mut self, mesh: &Mesh, out: &mut Mesh) {
|
||||
if !mesh.is_valid() {
|
||||
crate::epaint_assert!(false, "Invalid Mesh in Shape::Mesh");
|
||||
debug_assert!(false, "Invalid Mesh in Shape::Mesh");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1554,7 +1554,7 @@ impl Tessellator {
|
||||
}
|
||||
|
||||
if *fill != Color32::TRANSPARENT {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
closed,
|
||||
"You asked to fill a path that is not closed. That makes no sense."
|
||||
);
|
||||
@@ -1760,7 +1760,7 @@ impl Tessellator {
|
||||
color = color.gamma_multiply(*opacity_factor);
|
||||
}
|
||||
|
||||
crate::epaint_assert!(color != Color32::PLACEHOLDER, "A placeholder color made it to the tessellator. You forgot to set a fallback color.");
|
||||
debug_assert!(color != Color32::PLACEHOLDER, "A placeholder color made it to the tessellator. You forgot to set a fallback color.");
|
||||
|
||||
let offset = if *angle == 0.0 {
|
||||
pos.to_vec2()
|
||||
@@ -1864,7 +1864,7 @@ impl Tessellator {
|
||||
self.scratchpad_path.add_open_points(points);
|
||||
}
|
||||
if fill != Color32::TRANSPARENT {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
closed,
|
||||
"You asked to fill a path that is not closed. That makes no sense."
|
||||
);
|
||||
@@ -1946,7 +1946,7 @@ impl Tessellator {
|
||||
|
||||
for clipped_primitive in &clipped_primitives {
|
||||
if let Primitive::Mesh(mesh) = &clipped_primitive.primitive {
|
||||
crate::epaint_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh");
|
||||
debug_assert!(mesh.is_valid(), "Tessellator generated invalid Mesh");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -890,7 +890,7 @@ impl Galley {
|
||||
pcursor_it.offset += row.char_count_including_newline();
|
||||
}
|
||||
}
|
||||
crate::epaint_assert!(ccursor_it == self.end().ccursor);
|
||||
debug_assert!(ccursor_it == self.end().ccursor);
|
||||
Cursor {
|
||||
ccursor: ccursor_it, // clamp
|
||||
rcursor: self.end_rcursor(),
|
||||
|
||||
@@ -49,7 +49,7 @@ impl TextureManager {
|
||||
pub fn set(&mut self, id: TextureId, delta: ImageDelta) {
|
||||
if let Some(meta) = self.metas.get_mut(&id) {
|
||||
if let Some(pos) = delta.pos {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
pos[0] + delta.image.width() <= meta.size[0]
|
||||
&& pos[1] + delta.image.height() <= meta.size[1],
|
||||
"Partial texture update is outside the bounds of texture {id:?}",
|
||||
@@ -63,7 +63,7 @@ impl TextureManager {
|
||||
}
|
||||
self.delta.set.push((id, delta));
|
||||
} else {
|
||||
crate::epaint_assert!(false, "Tried setting texture {id:?} which is not allocated");
|
||||
debug_assert!(false, "Tried setting texture {id:?} which is not allocated");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ impl TextureManager {
|
||||
self.delta.free.push(id);
|
||||
}
|
||||
} else {
|
||||
crate::epaint_assert!(false, "Tried freeing texture {id:?} which is not allocated");
|
||||
debug_assert!(false, "Tried freeing texture {id:?} which is not allocated");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ impl TextureManager {
|
||||
if let Some(meta) = self.metas.get_mut(&id) {
|
||||
meta.retain_count += 1;
|
||||
} else {
|
||||
crate::epaint_assert!(
|
||||
debug_assert!(
|
||||
false,
|
||||
"Tried retaining texture {id:?} which is not allocated",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user