Better bounds checking in layer numbers

This commit is contained in:
Cherubim 2019-05-28 14:38:19 +02:00
parent 6bf3b1509a
commit e1bb783bcd
No known key found for this signature in database
GPG key ID: 6E03595319423F70

View file

@ -92,8 +92,11 @@ class FilamentChange(Script):
layer_targets = layer_nums.split(",") layer_targets = layer_nums.split(",")
if len(layer_targets) > 0: if len(layer_targets) > 0:
for layer_num in layer_targets: for layer_num in layer_targets:
layer_num = int(layer_num.strip()) + 1 try:
if layer_num <= len(data): layer_num = int(layer_num.strip()) + 1 #Needs +1 because the 1st layer is reserved for start g-code.
except ValueError: #Layer number is not an integer.
continue
if 0 < layer_num < len(data):
data[layer_num] = color_change + data[layer_num] data[layer_num] = color_change + data[layer_num]
return data return data