From 67d66905ba1199a161b580292c0837811088a2c4 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Sun, 26 Mar 2017 14:08:07 +0200 Subject: [PATCH 1/2] Fix crash when editing material diameter While editing the diameter value in the materials pane, it can happen that the radius evaluates to 0. This led to a division by zero. Fixes https://github.com/Ultimaker/Cura/issues/1582 --- cura/PrintInformation.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cura/PrintInformation.py b/cura/PrintInformation.py index d2476f25b6..e6ed313db2 100644 --- a/cura/PrintInformation.py +++ b/cura/PrintInformation.py @@ -126,7 +126,6 @@ class PrintInformation(QObject): return # Material amount is sent as an amount of mm^3, so calculate length from that - r = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 self._material_lengths = [] self._material_weights = [] self._material_costs = [] @@ -161,8 +160,13 @@ class PrintInformation(QObject): else: cost = 0 + radius = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 + if radius != 0: + length = round((amount / (math.pi * radius ** 2)) / 1000, 2) + else: + length = 0 self._material_weights.append(weight) - self._material_lengths.append(round((amount / (math.pi * r ** 2)) / 1000, 2)) + self._material_lengths.append(length) self._material_costs.append(cost) self.materialLengthsChanged.emit() From ba06f06cd0e5dfbf085826d14b9f270646fdab5c Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Tue, 28 Mar 2017 20:17:51 +0200 Subject: [PATCH 2/2] Optimize code --- cura/PrintInformation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/PrintInformation.py b/cura/PrintInformation.py index e6ed313db2..b066a1693d 100644 --- a/cura/PrintInformation.py +++ b/cura/PrintInformation.py @@ -126,6 +126,7 @@ class PrintInformation(QObject): return # Material amount is sent as an amount of mm^3, so calculate length from that + radius = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 self._material_lengths = [] self._material_weights = [] self._material_costs = [] @@ -160,7 +161,6 @@ class PrintInformation(QObject): else: cost = 0 - radius = Application.getInstance().getGlobalContainerStack().getProperty("material_diameter", "value") / 2 if radius != 0: length = round((amount / (math.pi * radius ** 2)) / 1000, 2) else: