Skip to content

Commit dac576a

Browse files
committed
FIX: Handle None G-code lines to prevent script crash.
The script was breaking when some G-code lines were None. This commit adds a safeguard, but the root cause still needs investigation. Thanks @jungletek for the report and code changes! Reference: #2 (comment)
1 parent c1fd159 commit dac576a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

bricklayers.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,8 @@ def process_gcode(self, gcode_stream):
16201620

16211621
else: # When it layers to be ignored:
16221622
# This Perimiter is part of a Layer that should NOT be modified. Just append:
1623-
buffer_lines.append(myline)
1623+
if myline is not None:
1624+
buffer_lines.append(myline)
16241625

16251626

16261627

@@ -1786,9 +1787,9 @@ def process_gcode(self, gcode_stream):
17861787
#outfile.writelines([gcodeline.to_gcode() for gcodeline in buffer_lines]) #OLD WAY
17871788
# Generator way:
17881789
if not self.yield_objects:
1789-
yield from (gcodeline.to_gcode() for gcodeline in buffer_lines)
1790+
yield from (gcodeline.to_gcode() for gcodeline in buffer_lines if gcodeline is not None)
17901791
else:
1791-
yield from buffer_lines
1792+
yield from (buffer_line for buffer_line in buffer_lines if buffer_line is not None)
17921793
buffer_lines.clear()
17931794

17941795
# Clear the structure for deffered perimeters, ready for the next Layer:
@@ -1802,7 +1803,8 @@ def process_gcode(self, gcode_stream):
18021803
#
18031804
if not feature.internal_perimeter:
18041805
# Adds all the normal lines to the buffer:
1805-
buffer_lines.append(myline)
1806+
if myline is not None:
1807+
buffer_lines.append(myline)
18061808

18071809
# Exception for pretty visualization on PrusaSlicer and OrcaSlicer preview:
18081810
# Forces a "Width" after an External Perimeter begins, to make them look like they actually ARE.
@@ -2172,7 +2174,8 @@ def expand_ranges(ranges):
21722174

21732175
# Write processed G-code to the output file
21742176
for processed_line in processed_gcode:
2175-
outfile.write(processed_line)
2177+
if processed_line is not None: # TODO: why does some people get a None line?!
2178+
outfile.write(processed_line)
21762179

21772180

21782181
# If using a temporary file, replace the original input_file

0 commit comments

Comments
 (0)