{"record":{"id":"bbeb5a9f2bb5919e","repo":"SubtitleEdit/subtitleedit","slug":"bounding-box-array-centerperx-centerpery-perwid","errorCode":null,"errorMessage":"Bounding box array [centerPerX, centerPerY, perWidth, perHeight] not set or invalid","messagePattern":"Bounding box array \\[centerPerX, centerPerY, perWidth, perHeight\\] not set or invalid","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Ocr/GoogleLens/BoundingBox.cs","lineNumber":19,"sourceCode":"using System;\n\nnamespace Nikse.SubtitleEdit.Logic.Ocr.GoogleLens;\n\npublic class BoundingBox\n{\n    private readonly int[] _imageDimensions;\n\n    public double CenterPerX { get; }\n    public double CenterPerY { get; }\n    public double PerWidth { get; }\n    public double PerHeight { get; }\n    public PixelCoordinates PixelCoords { get; }\n\n    public BoundingBox(double[] box, int[] imageDimensions)\n    {\n        if (box == null || box.Length != 4)\n        {\n            throw new ArgumentException(\"Bounding box array [centerPerX, centerPerY, perWidth, perHeight] not set or invalid\");\n        }\n        \n        if (imageDimensions == null || imageDimensions.Length != 2)\n        {\n            throw new ArgumentException(\"Image dimensions [width, height] not set or invalid\");\n        }\n\n        _imageDimensions = imageDimensions;\n        CenterPerX = box[0];\n        CenterPerY = box[1];\n        PerWidth = box[2];\n        PerHeight = box[3];\n        PixelCoords = ToPixelCoords();\n    }\n\n    private PixelCoordinates ToPixelCoords()\n    {\n        var imgWidth = _imageDimensions[0];","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Ocr/GoogleLens/BoundingBox.cs#L1-L37","documentation":"Thrown by the BoundingBox constructor when the box argument is null or does not have exactly 4 elements. The array is expected to hold [centerPerX, centerPerY, perWidth, perHeight] as normalized (0-1) coordinates parsed from Google Lens output; a wrong shape makes the downstream ToPixelCoords math meaningless, so construction fails fast.","triggerScenarios":"Constructing new BoundingBox(box, imageDimensions) where box is null, empty, or has fewer/more than 4 entries. Commonly happens when Google Lens returned no region for a detected object, or when ParseResult's region extraction yielded a null/short array.","commonSituations":"A Lens response where a text region has no bounding data; an upstream parsing change that altered the array shape; defensive code passing a default null before checking Lens output.","solutions":["Validate the region array has Length == 4 before constructing BoundingBox.","Skip/null-check Lens regions that lack bounding data rather than constructing a box.","If ParseResult is the source, ensure the region Select only emits arrays of length 4.","Guard the upstream double[] with a null check at the call site."],"exampleFix":"// before\nvar box = new BoundingBox(region, dims);\n\n// after\nif (region == null || region.Length != 4) continue;\nvar box = new BoundingBox(region, dims);","handlingStrategy":"validation","validationCode":"if (box == null || box.Length != 4)\n    return; // or skip this region\nvar bb = new BoundingBox(box, imageDimensions);","typeGuard":"static bool IsValidBox(double[] box) => box != null && box.Length == 4;","tryCatchPattern":"try { var bb = new BoundingBox(region, dims); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Bounding box array\")) { continue; }","preventionTips":["Filter Lens regions to those with a 4-element double[] before constructing BoundingBox.","Null-check region arrays from ParseResult.","Log skipped regions to spot upstream parsing regressions.","Centralize the length-4 check in a helper."],"tags":["google-lens","ocr","bounding-box","validation","argument"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}