{"record":{"id":"308a9b4a56acf7fb","repo":"SixLabors/ImageSharp","slug":"the-oilpaintprocessor-failed-the-most-likely-reason-is-that","errorCode":null,"errorMessage":"The OilPaintProcessor failed. The most likely reason is that a pixel component was outside of its' allowed range.","messagePattern":"The OilPaintProcessor failed\\. The most likely reason is that a pixel component was outside of its' allowed range\\.","errorType":"exception","errorClass":"ImageProcessingException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs","lineNumber":55,"sourceCode":"    {\n        int levels = Math.Clamp(this.definition.Levels, 1, 255);\n        int brushSize = Math.Clamp(this.definition.BrushSize, 1, Math.Min(source.Width, source.Height));\n\n        using Buffer2D<TPixel> targetPixels = this.Configuration.MemoryAllocator.Allocate2D<TPixel>(source.Size);\n\n        source.CopyTo(targetPixels);\n\n        RowIntervalOperation operation = new(this.SourceRectangle, targetPixels, source.PixelBuffer, this.Configuration, brushSize >> 1, levels);\n        try\n        {\n            ParallelRowIterator.IterateRowIntervals(\n            this.Configuration,\n            this.SourceRectangle,\n            in operation);\n        }\n        catch (Exception ex)\n        {\n            throw new ImageProcessingException(\"The OilPaintProcessor failed. The most likely reason is that a pixel component was outside of its' allowed range.\", ex);\n        }\n\n        Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels);\n    }\n\n    /// <summary>\n    /// A <see langword=\"struct\"/> implementing the convolution logic for <see cref=\"OilPaintingProcessor{T}\"/>.\n    /// </summary>\n    private readonly struct RowIntervalOperation : IRowIntervalOperation\n    {\n        private readonly Rectangle bounds;\n        private readonly Buffer2D<TPixel> targetPixels;\n        private readonly Buffer2D<TPixel> source;\n        private readonly Configuration configuration;\n        private readonly int radius;\n        private readonly int levels;\n\n        [MethodImpl(InliningOptions.ShortMethod)]","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs#L37-L73","documentation":"OilPaintingProcessor wraps its per-frame pixel operations in try/catch and rethrows any inner failure as ImageProcessingException. The kernel-based levels accumulation can only fail if a computed level index falls outside the levels array, i.e. a pixel component was out of range. This usually indicates corrupted input pixel data or an internal kernel problem, so the library reports the original exception as inner.","triggerScenarios":"Calling Mutate/Apply with OilPaintingProcessor when the underlying pixel buffer contains values outside the component range, or when the levels lookup in the parallel kernel throws (index mismatch between pixel type and levels array).","commonSituations":"Processing images whose pixel data was produced by buggy custom IPixel implementations or raw buffer manipulation; running on images with unusual pixel formats converted unexpectedly; downstream memory corruption from other unsafe code.","solutions":["Inspect the InnerException to find the real failure","Ensure input pixels come from normal Image<TPixel> decoding, not hand-written buffer writes","If a custom IPixel<TPixel> implementation is involved, fix its component clamping so all components stay within [0,1] scaled range","Reduce the oil paint levels parameter and retry to see if the failure is level-count dependent"],"exampleFix":"// before\nimage.Mutate(x => x.OilPaint(levels, brushSize));\n// after\ntry\n{\n    image.Mutate(x => x.OilPaint(levels, brushSize));\n}\ncatch (ImageProcessingException ex)\n{\n    // inspect ex.InnerException for the real pixel-level failure\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"if (image is null || image.Width == 0 || image.Height == 0) throw new InvalidOperationException(\"Image not loaded.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    image.Mutate(x => x.OilPaint(levels, brushSize));\n}\ncatch (ImageProcessingException ex)\n{\n    // log ex.InnerException.StackTrace for the underlying pixel failure\n    throw;\n}","preventionTips":["Load images with the standard Image.Load/Image.Load<TPixel> APIs instead of manual buffer manipulation","Keep pixel data within [0,1] scaled component range for custom IPixel implementations","Verify the exception's InnerException — the outer message is only a wrapper","Test with representative images before deploying oil-paint processing to production"],"tags":["oil-paint","image-processing","pixel-data"],"backgroundTag":"invalid-argument-value","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}