TheAlgorithms/C-Sharp · error
should be greater than zero
Error message
{nameof(bitmapWidth)} should be greater than zero What it means
Mandelbrot.GetBitmap renders the fractal into an SKBitmap sized bitmapWidth x bitmapHeight. The library first validates bitmapWidth is strictly positive and throws ArgumentOutOfRangeException otherwise, because a non-positive width makes bitmap creation and per-pixel math meaningless.
Solutions
- Pass a bitmapWidth > 0 (e.g. 800)
- Validate width before the call and fall back to a sensible default
- Sanitize any parsed input so 0/negative values cannot reach the call
Example fix
// before var bmp = Mandelbrot.GetBitmap(width, height); // after var bmp = Mandelbrot.GetBitmap(width > 0 ? width : 800, height);
Defensive patterns
Strategy: validation
Validate before calling
if (bitmapWidth <= 0) throw new ArgumentException("bitmapWidth must be positive", nameof(bitmapWidth)); Type guard
static bool IsValidDimension(int d) => d > 0;
Try / catch
try { var bmp = Mandelbrot.GetBitmap(width, height); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "bitmapWidth")
{
// retry with default width
} Prevention
- Clamp dimensions with Math.Max(1, value) before rendering
- Check that computed sizes from layout/window code are positive
- Validate user- or config-supplied sizes at ingestion
When it happens
Trigger: Calling Algorithms.Other.Mandelbrot.GetBitmap with bitmapWidth <= 0, e.g. GetBitmap(0, 600) or a computed width of 0 or negative from caller code.
Common situations: Width derived from a resized window or container that reported 0; config or query-string values parsed incorrectly; callers omitting the value and relying on a 0 default.
Related errors
- should be greater than zero
- should be greater than zero
- should be greater than zero
- Invalid block size
- Not enough space in input array for padding
AI-assisted analysis of TheAlgorithms/C-Sharp@96e2905cab (2026-09-13).
Data as JSON: /api/errors/901de110e83e4c00.
Report an issue: GitHub.
Appendix: source
Thrown at Algorithms/Other/Mandelbrot.cs:54
/// <param name="bitmapHeight">The height of the rendered bitmap.</param>
/// <param name="figureCenterX">The x-coordinate of the center of the figure.</param>
/// <param name="figureCenterY">The y-coordinate of the center of the figure.</param>
/// <param name="figureWidth">The width of the figure.</param>
/// <param name="maxStep">Maximum number of steps to check for divergent behavior.</param>
/// <param name="useDistanceColorCoding">Render in color or black and white.</param>
/// <returns>The bitmap of the rendered Mandelbrot set.</returns>
public static SKBitmap GetBitmap(
int bitmapWidth = 800,
int bitmapHeight = 600,
double figureCenterX = -0.6,
double figureCenterY = 0,
double figureWidth = 3.2,
int maxStep = 50,
bool useDistanceColorCoding = true)
{
if (bitmapWidth <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(bitmapWidth),
$"{nameof(bitmapWidth)} should be greater than zero");
}
if (bitmapHeight <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(bitmapHeight),
$"{nameof(bitmapHeight)} should be greater than zero");
}
if (maxStep <= 0)
{
throw new ArgumentOutOfRangeException(
nameof(maxStep),
$"{nameof(maxStep)} should be greater than zero");
}
View on GitHub (pinned to 96e2905cab)