From cbfe10a748ae6caf2abb2da19d7c7351587e7c04 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Mon, 8 Apr 2019 13:36:48 +0200 Subject: [PATCH] Prevent a zeroDivision error from crashing the usb printing This fixes #5592 --- plugins/USBPrinting/USBPrinterOutputDevice.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index 0c195e9017..667a969e87 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -371,10 +371,17 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._sendCommand("N%d%s*%d" % (self._gcode_position, line, checksum)) - progress = (self._gcode_position / len(self._gcode)) + print_job = self._printers[0].activePrintJob + try: + progress = self._gcode_position / len(self._gcode) + except ZeroDivisionError: + # There is nothing to send! + if print_job is not None: + print_job.updateState("error") + return elapsed_time = int(time() - self._print_start_time) - print_job = self._printers[0].activePrintJob + if print_job is None: controller = GenericOutputController(self) controller.setCanUpdateFirmware(True)