FyroxEngine/Fyrox · warning

Terrain brush operation dropped due to sanity limit

Error message

Terrain brush operation dropped due to sanity limit: {area}

What it means

Terrain brush operations compute the affected pixel rectangle; within_size_limit rejects strokes whose affected area exceeds BRUSH_PIXEL_SANITY_LIMIT, logging this warning and dropping the operation to keep the editor responsive. It prevents pathological strokes (e.g. gigantic brush radius or extreme zoom) from stalling the brush thread.

Solutions

  1. Reduce the brush size/radius in the terrain editor before painting.
  2. Zoom in or paint in smaller sections so the per-stroke affected area stays under the sanity limit.
  3. If legitimate large-area edits are needed, apply them in multiple smaller strokes or via script rather than one giant brush stamp.
Defensive patterns

Strategy: validation

Validate before calling

// Clamp brush size before issuing strokes:
let max_brush = (BRUSH_PIXEL_SANITY_LIMIT as f32).sqrt() as i32;
let brush_size = brush_size.min(max_brush);

Prevention

When it happens

Trigger: Performing a terrain brush stroke where the brush's affected Rect<i32> has size.x * size.y > BRUSH_PIXEL_SANITY_LIMIT — typically from a huge brush size or a camera/terrain transform that magnifies the stroke footprint.

Common situations: Editor users setting an enormous brush radius; degenerate camera setups painting the whole terrain at once; strokes spanning multiple chunk boundaries over a large terrain.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/65638f183882a5dc. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-impl/src/scene/terrain/brushstroke/mod.rs:824

            transform: Matrix2::identity(),
            hardness: 0.0,
            alpha: 1.0,
            shape: Default::default(),
            mode: Default::default(),
            target: Default::default(),
        }
    }
}

/// Verify that the brush operation is not so big that it could cause the editor to freeze.
/// The user can type in any size of brush they please, even disastrous sizes, and
/// this check prevents the editor from breaking.
fn within_size_limit(bounds: &Rect<i32>) -> bool {
    let size = bounds.size;
    let area = size.x * size.y;
    let accepted = area <= BRUSH_PIXEL_SANITY_LIMIT;
    if !accepted {
        Log::warn(format!(
            "Terrain brush operation dropped due to sanity limit: {area}"
        ))
    }
    accepted
}

impl Brush {
    /// Send the pixels for this brush to the brush thread.
    /// - `position`: The position of the brush in texture pixels.
    /// - `scale`: The size of each pixel in local 2D space. This is used
    /// to convert the brush's radius from local 2D to pixels.
    /// - `value`: The brush's value. The meaning of this number depends on the brush.
    /// - `draw_pixel`: The function that will draw the pixels to the terrain.
    pub fn stamp<F>(&self, position: Vector2<f32>, scale: Vector2<f32>, mut draw_pixel: F)
    where
        F: FnMut(Vector2<i32>, f32),
    {
        let mut transform = self.transform;

View on GitHub (pinned to 76c91aad8e)