Skip to content

Commit b4d3aab

Browse files
committed
fix: sanitize n_colors
1 parent f047162 commit b4d3aab

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/e3sm_compareview/view_manager.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,18 @@ def update_color_preset(self, name, invert, log_scale, n_colors=255):
194194
self.lut.MapControlPointsToLogSpace()
195195
self.lut.UseLogScale = 1
196196

197-
self.lut.NumberOfTableValues = n_colors
197+
# VNumberInput can transiently emit None/invalid while editing.
198+
# Keep the LUT update resilient by clamping to a valid integer range.
199+
resolved_n_colors = n_colors if n_colors is not None else self.config.n_colors
200+
try:
201+
resolved_n_colors = int(resolved_n_colors)
202+
except (TypeError, ValueError):
203+
resolved_n_colors = 255
204+
resolved_n_colors = max(2, min(255, resolved_n_colors))
205+
if self.config.n_colors != resolved_n_colors:
206+
self.config.n_colors = resolved_n_colors
207+
208+
self.lut.NumberOfTableValues = resolved_n_colors
198209

199210
self.config.lut_img = lut_to_img(self.lut)
200211

0 commit comments

Comments
 (0)