From 18568d6ba70dc7201a5d8fcada6a5410d381c215 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 16 May 2023 15:16:48 +0500 Subject: [PATCH] Schedule cells limit without print range to prevent system freeze MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What I've found that sometimes you might get into situation (especially if .ods was created / processed in Excel) you might get a lot unnecessary columns and rows (in fact excel always seems to save 1048576x16384 table) and trying to print this kind of table results in investing a lot of RAM into it and possible system freeze. Now there is a check if table has more than 10000 cells (number is completely made up 😁) then it would require user to define print range in the table to prevent the issue. --- .../bim/module/drawing/scheduler.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/scheduler.py b/src/blenderbim/blenderbim/bim/module/drawing/scheduler.py index dd5e97a38e..38fbfa7f53 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/scheduler.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/scheduler.py @@ -154,7 +154,20 @@ class Scheduler: min_rc, max_rc = [a1_to_rc(cell.rsplit(".", 1)[1]) for cell in print_range.split(":")] else: # fallback if print range is not defined - min_rc, max_rc = (0,0), (1048576, 16384) + n_rows = len(row_heights) + n_cols = len(column_widths) + n_cells = len(row_heights) * len(column_widths) + cells_limit = 10000 + if n_cells >= cells_limit: + raise Exception( + f"You were about to build a very big table with number of cells more than {cells_limit}.\n" + f"In fact it is {n_rows} rows x {n_cols} cols = {n_cells} cells \n" + "and the operation was stopped to prevent system freeze.\n" + "Please define print range in .ods file to proceede\n" + "(needed to make sure printed table will have reasonable size)." + ) + + min_rc, max_rc = (0, 0), (1048576, 16384) min_row, min_col = min_rc max_row, max_col = max_rc @@ -263,10 +276,11 @@ class Scheduler: tri += 1 y += height - total_width = sum(column_widths) + (self.margin * 2) + total_width = x + self.margin + total_height = y + self.margin self.svg["width"] = "{}mm".format(total_width) - self.svg["height"] = "{}mm".format(y) - self.svg["viewBox"] = "0 0 {} {}".format(total_width, y) + self.svg["height"] = "{}mm".format(total_height) + self.svg["viewBox"] = "0 0 {} {}".format(total_width, total_height) self.svg.save(pretty=True) def get_style(self, style_name, styles):