{"record":{"id":"0f8a4a0b7e875f03","repo":"d2phap/ImageGlass","slug":"bad-configuration-parameters","errorCode":null,"errorMessage":"Bad configuration parameters","messagePattern":"Bad configuration parameters","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"v9/Components/ImageGlass.WebP/WebPWrapper.cs","lineNumber":873,"sourceCode":"    /// <param name=\"config\">Configuration for encode</param>\n    /// <param name=\"info\">True if need encode info.</param>\n    /// <returns>Compressed data</returns>\n    private byte[] AdvancedEncode(Bitmap bmp, WebPConfig config, bool info)\n    {\n        byte[]? rawWebP = null;\n        byte[]? dataWebp = null;\n        var wpic = new WebPPicture();\n        BitmapData? bmpData = null;\n        var stats = new WebPAuxStats();\n        var ptrStats = IntPtr.Zero;\n        var pinnedArrayHandle = new GCHandle();\n        int dataWebpSize;\n\n        try\n        {\n            // Validate the configuration\n            if (LibWebp.WebPValidateConfig(ref config) != 1)\n                throw new Exception(\"Bad configuration parameters\");\n\n            // test bmp\n            if (bmp.Width == 0 || bmp.Height == 0)\n                throw new ArgumentException(\"Bitmap contains no data.\", nameof(bmp));\n            if (bmp.Width > WEBP_MAX_DIMENSION || bmp.Height > WEBP_MAX_DIMENSION)\n                throw new NotSupportedException($\"Bitmap's dimension is too large. Max is {WEBP_MAX_DIMENSION}x{WEBP_MAX_DIMENSION} pixels.\");\n            if (bmp.PixelFormat != PixelFormat.Format24bppRgb && bmp.PixelFormat != PixelFormat.Format32bppArgb)\n                throw new NotSupportedException(\"Only support Format24bppRgb and Format32bppArgb pixelFormat.\");\n\n            // Setup the input data, allocating a the bitmap, width and height\n            bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);\n            if (LibWebp.WebPPictureInitInternal(ref wpic) != 1)\n                throw new Exception(\"Can't initialize WebPPictureInit\");\n            wpic.width = (int)bmp.Width;\n            wpic.height = (int)bmp.Height;\n            wpic.use_argb = 1;\n\n            if (bmp.PixelFormat == PixelFormat.Format32bppArgb)","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.WebP/WebPWrapper.cs#L855-L891","documentation":"Thrown by AdvancedEncode (the shared advanced encoder used by EncodeLossy/EncodeLossless/EncodeNearLossless advanced overloads) when LibWebp.WebPValidateConfig(ref config) != 1. WebPValidateConfig checks that the WebPConfig fields are internally consistent; a non-1 result means the assembled configuration is illegal (e.g. conflicting fields, out-of-range method/pass, or an incompatible lossless/lossy combination).","triggerScenarios":"Reaching AdvancedEncode with a config whose field combination fails WebPValidateConfig — bad method value, partitions/segments out of range, lossless flag mixed with lossy-only options, or near_lossless set without lossless=1.","commonSituations":"The advanced overloads in this wrapper set many config fields (method, segments, partitions, alpha_filtering, near_lossless, exact) directly; any combination libwebp rejects produces this error before the bitmap is even inspected.","solutions":["Inspect which advanced overload you called and whether its forced fields are compatible with your libwebp version.","Update libwebp to a version that accepts the wrapper's full config (partitions=3, segments=4, preprocessing=4 require newer builds).","Use the simple APIs (EncodeLossy(bmp, quality) / EncodeLossless(bmp)) that bypass WebPValidateConfig.","Reproduce the config and call WebPValidateConfig yourself to isolate the offending field."],"exampleFix":"// before\nvar bytes = webp.EncodeLossy(bmp, quality, speed, info: true); // advanced, may produce bad config\n\n// after\nvar bytes = webp.EncodeLossy(bmp, quality); // simple API, no WebPValidateConfig risk","handlingStrategy":"try-catch","validationCode":"// Advanced config is built internally; pre-validate by preferring the simple API\n// unless you need advanced tuning. Clamp speed/quality before calling.\nint s = Math.Clamp(speed, 0, 9); int q = Math.Clamp(quality, 0, 100);","typeGuard":null,"tryCatchPattern":"try { var bytes = webp.EncodeLossy(bmp, quality, speed); }\ncatch (Exception ex) when (ex.Message == \"Bad configuration parameters\")\n{ var bytes = webp.EncodeLossy(bmp, quality); /* simple API */ }","preventionTips":["Use the simple APIs unless you need advanced tuning.","Update libwebp to accept the wrapper's full config set.","Reproduce the failing config and call WebPValidateConfig to isolate the offending field."],"tags":["webp","encoding","config-validation","advanced-api","native-abi"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}