TheAlgorithms/C-Sharp · error
should be greater than zero
Error message
{nameof(maxStep)} should be greater than zero What it means
Mandelbrot.GetBitmap requires maxStep, the iteration cap controlling escape-time detail, to be strictly positive. After validating width and height it throws ArgumentOutOfRangeException when maxStep <= 0, since the per-pixel loop would otherwise never terminate meaningfully.
Solutions
- Pass maxStep >= 1 (the default is 50)
- Validate the iteration count before calling and clamp to at least 1
- Fix the config/parse path that yielded 0 or a negative value
Example fix
// before var bmp = Mandelbrot.GetBitmap(800, 600, 3.2, steps); // after var bmp = Mandelbrot.GetBitmap(800, 600, 3.2, Math.Max(1, steps));
Defensive patterns
Strategy: validation
Validate before calling
if (maxStep <= 0) throw new ArgumentException("maxStep must be positive", nameof(maxStep)); Type guard
static bool IsValidIterationCount(int n) => n > 0;
Try / catch
try { var bmp = Mandelbrot.GetBitmap(w, h, figureWidth, steps); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "maxStep")
{
// retry with default maxStep = 50
} Prevention
- Clamp iteration counts to at least 1
- Guard parsed config integers against 0/negative defaults
- Test tuning parameter boundaries (0, 1, large values)
When it happens
Trigger: Calling Algorithms.Other.Mandelbrot.GetBitmap with maxStep <= 0, e.g. GetBitmap(800, 600, 3.2, 0) or a negative step count passed from tuning code.
Common situations: Experimenting with iteration depth and passing 0; parsing a 'max iterations' config value where an empty field became 0; sign errors in generated parameters.
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/0d19c50e7dbeb77e.
Report an issue: GitHub.
Appendix: source
Thrown at Algorithms/Other/Mandelbrot.cs:68
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");
}
var bitmap = new SKBitmap(bitmapWidth, bitmapHeight);
var figureHeight = figureWidth / bitmapWidth * bitmapHeight;
// loop through the bitmap-coordinates
for (var bitmapX = 0; bitmapX < bitmapWidth; bitmapX++)
{
for (var bitmapY = 0; bitmapY < bitmapHeight; bitmapY++)
{
// determine the figure-coordinates based on the bitmap-coordinates
var figureX = figureCenterX + ((double)bitmapX / bitmapWidth - 0.5) * figureWidth;
var figureY = figureCenterY + ((double)bitmapY / bitmapHeight - 0.5) * figureHeight;
var distance = GetDistance(figureX, figureY, maxStep);
View on GitHub (pinned to 96e2905cab)