From 59b9ca50eec6d54f3dfc770d1d938b18c9d8478c Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sun, 29 Mar 2026 01:25:22 -0700 Subject: [PATCH] Guard against divide by zero and out-of-bounds --- modules/image/grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/image/grid.py b/modules/image/grid.py index 0a2430142..4a3f38d6e 100644 --- a/modules/image/grid.py +++ b/modules/image/grid.py @@ -51,9 +51,9 @@ def get_grid_size(imgs: list, batch_size=1, rows: int | None = None, cols: int | return rows_int, cols_int # Set limits if rows is not None: - rows_int = min(rows, len(imgs)) + rows_int = max(min(rows, len(imgs)), 1) if cols is not None: - cols_int = min(cols, len(imgs)) + cols_int = max(min(cols, len(imgs)), 1) # Calculate if rows is None: rows_int = math.ceil(len(imgs) / cols_int)