mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Fix asynchronous bug if job gets cancelled
If the print job happens to get cancelled right after checking if the index is correct, but before actually reading the line, it would get an IndexError when trying to read the line since cancelling the job clears the _gcode list. This prevents that asynchronous issue by using the internal check in the list access to check that, and just uses an exception to check whether it's reached the end. Fixes Sentry issue CURA-QC.
This commit is contained in:
parent
5ccf8e412d
commit
1946615fff
1 changed files with 11 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2019 Ultimaker B.V.
|
||||
# Copyright (c) 2020 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import os
|
||||
|
@ -367,11 +367,18 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
|||
self._sendCommand("M84")
|
||||
|
||||
def _sendNextGcodeLine(self):
|
||||
if self._gcode_position >= len(self._gcode):
|
||||
"""
|
||||
Send the next line of g-code, at the current `_gcode_position`, via a
|
||||
serial port to the printer.
|
||||
|
||||
If the print is done, this sets `_is_printing` to `False` as well.
|
||||
"""
|
||||
try:
|
||||
line = self._gcode[self._gcode_position]
|
||||
except IndexError: # End of print, or print got cancelled.
|
||||
self._printers[0].updateActivePrintJob(None)
|
||||
self._is_printing = False
|
||||
return
|
||||
line = self._gcode[self._gcode_position]
|
||||
|
||||
if ";" in line:
|
||||
line = line[:line.find(";")]
|
||||
|
@ -401,7 +408,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
|
|||
if print_job is None:
|
||||
controller = GenericOutputController(self)
|
||||
controller.setCanUpdateFirmware(True)
|
||||
print_job = PrintJobOutputModel(output_controller=controller, name=CuraApplication.getInstance().getPrintInformation().jobName)
|
||||
print_job = PrintJobOutputModel(output_controller = controller, name = CuraApplication.getInstance().getPrintInformation().jobName)
|
||||
print_job.updateState("printing")
|
||||
self._printers[0].updateActivePrintJob(print_job)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue