{"record":{"id":"901de110e83e4c00","repo":"TheAlgorithms/C-Sharp","slug":"nameof-bitmapwidth-should-be-greater-than-zero-mandelbrot","errorCode":null,"errorMessage":"{nameof(bitmapWidth)} should be greater than zero","messagePattern":"(.+?) should be greater than zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/Mandelbrot.cs","lineNumber":54,"sourceCode":"    /// <param name=\"bitmapHeight\">The height of the rendered bitmap.</param>\n    /// <param name=\"figureCenterX\">The x-coordinate of the center of the figure.</param>\n    /// <param name=\"figureCenterY\">The y-coordinate of the center of the figure.</param>\n    /// <param name=\"figureWidth\">The width of the figure.</param>\n    /// <param name=\"maxStep\">Maximum number of steps to check for divergent behavior.</param>\n    /// <param name=\"useDistanceColorCoding\">Render in color or black and white.</param>\n    /// <returns>The bitmap of the rendered Mandelbrot set.</returns>\n    public static SKBitmap GetBitmap(\n        int bitmapWidth = 800,\n        int bitmapHeight = 600,\n        double figureCenterX = -0.6,\n        double figureCenterY = 0,\n        double figureWidth = 3.2,\n        int maxStep = 50,\n        bool useDistanceColorCoding = true)\n    {\n        if (bitmapWidth <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapWidth),\n                $\"{nameof(bitmapWidth)} should be greater than zero\");\n        }\n\n        if (bitmapHeight <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapHeight),\n                $\"{nameof(bitmapHeight)} should be greater than zero\");\n        }\n\n        if (maxStep <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(maxStep),\n                $\"{nameof(maxStep)} should be greater than zero\");\n        }\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/Mandelbrot.cs#L36-L72","documentation":"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.","triggerScenarios":"Calling Algorithms.Other.Mandelbrot.GetBitmap with bitmapWidth <= 0, e.g. GetBitmap(0, 600) or a computed width of 0 or negative from caller code.","commonSituations":"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.","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"],"exampleFix":"// before\nvar bmp = Mandelbrot.GetBitmap(width, height);\n// after\nvar bmp = Mandelbrot.GetBitmap(width > 0 ? width : 800, height);","handlingStrategy":"validation","validationCode":"if (bitmapWidth <= 0) throw new ArgumentException(\"bitmapWidth must be positive\", nameof(bitmapWidth));","typeGuard":"static bool IsValidDimension(int d) => d > 0;","tryCatchPattern":"try { var bmp = Mandelbrot.GetBitmap(width, height); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"bitmapWidth\")\n{\n    // retry with default width\n}","preventionTips":["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"],"tags":["argument-out-of-range","fractal","bitmap","csharp"],"backgroundTag":"argument-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}