{"record":{"id":"51bd9d5cc1aab2f9","repo":"LykosAI/StabilityMatrix","slug":"must-have-at-least-one-image","errorCode":null,"errorMessage":"Must have at least one image","messagePattern":"Must have at least one image","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Helpers/ImageProcessor.cs","lineNumber":32,"sourceCode":"    public static (int rows, int columns) GetGridDimensionsFromImageCount(int count)\n    {\n        if (count <= 1)\n            return (1, 1);\n        if (count == 2)\n            return (1, 2);\n\n        // Prefer one extra row over one extra column,\n        // the row count will be the floor of the square root\n        // and the column count will be floor of count / rows\n        var rows = (int)Math.Floor(Math.Sqrt(count));\n        var columns = (int)Math.Floor((double)count / rows);\n        return (rows, columns);\n    }\n\n    public static SKImage CreateImageGrid(IReadOnlyList<SKImage> images, int spacing = 0)\n    {\n        if (images.Count == 0)\n            throw new ArgumentException(\"Must have at least one image\");\n\n        var (rows, columns) = GetGridDimensionsFromImageCount(images.Count);\n\n        var singleWidth = images[0].Width;\n        var singleHeight = images[0].Height;\n\n        // Make output image\n        using var output = new SKBitmap(\n            singleWidth * columns + spacing * (columns - 1),\n            singleHeight * rows + spacing * (rows - 1)\n        );\n\n        // Draw images\n        using var canvas = new SKCanvas(output);\n\n        foreach (\n            var (row, column) in Enumerable.Range(0, rows).Product(Enumerable.Range(0, columns))\n        )","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Helpers/ImageProcessor.cs#L14-L50","documentation":"CreateImageGrid composites a list of SKImages into a grid and cannot do so with zero images: it indexes images[0] for dimensions and computes grid dimensions from the count. An empty list is treated as a programming/caller error and ArgumentException is thrown immediately.","triggerScenarios":"Calling ImageProcessor.CreateImageGrid with an empty IReadOnlyList<SKImage> — e.g. a preview grid built from a directory that yielded no decodable images, or a filter that removed all images before the grid step.","commonSituations":"Empty output folder or failed image loads when creating preview grids; caller passes a filtered list that ends up empty; test code constructs the grid before seeding images.","solutions":["Check images.Count > 0 before calling CreateImageGrid and skip/skip-and-log the grid step when empty.","Fix the upstream image loading/filtering so at least one image reaches the grid step.","For UI grids, show an empty-state placeholder instead of attempting to compose a grid."],"exampleFix":"// before\nvar grid = ImageProcessor.CreateImageGrid(images);\n// after\nvar grid = images.Count > 0 ? ImageProcessor.CreateImageGrid(images) : null;","handlingStrategy":"validation","validationCode":"if (images is null || images.Count == 0)\n    return null; // or show empty state","typeGuard":"static bool HasImages(IReadOnlyList<SKImage> imgs) => imgs is { Count: > 0 };","tryCatchPattern":"try { grid = ImageProcessor.CreateImageGrid(images); }\ncatch (ArgumentException ex) when (ex.Message == \"Must have at least one image\")\n{ grid = null; ShowEmptyState(); }","preventionTips":["Validate collection counts at API boundaries before composing grids.","Handle empty load/filter results explicitly instead of falling through to grid composition.","Add unit tests covering zero-image grid input."],"tags":["skiasharp","argument-validation","empty-collection","image-grid"],"backgroundTag":"empty-required-field","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}