Commit a6b9c72d authored by Guillaume Seguin's avatar Guillaume Seguin

Protect light gcode model as well with locks

parent aa2da210
......@@ -507,11 +507,11 @@ class GcodeModel(Model):
yield layer_idx
layer_idx += 1
with self.lock:
self.dims = ((model_data.xmin, model_data.xmax, model_data.width),
(model_data.ymin, model_data.ymax, model_data.depth),
(model_data.zmin, model_data.zmax, model_data.height))
with self.lock:
self.travels.resize(travel_vertex_k, refcheck = False)
self.vertices.resize(vertex_k, refcheck = False)
self.colors.resize(color_k, refcheck = False)
......@@ -735,6 +735,7 @@ class GcodeModelLight(Model):
self.printed_until = -1
self.only_current = False
while layer_idx < len(model_data.all_layers):
with self.lock:
nlines = len(model_data)
if nlines * 6 != vertices.size:
self.vertices.resize(nlines * 6, refcheck = False)
......@@ -784,6 +785,7 @@ class GcodeModelLight(Model):
yield layer_idx
layer_idx += 1
with self.lock:
self.dims = ((model_data.xmin, model_data.xmax, model_data.width),
(model_data.ymin, model_data.ymax, model_data.depth),
(model_data.zmin, model_data.zmax, model_data.height))
......@@ -829,11 +831,14 @@ class GcodeModelLight(Model):
# ------------------------------------------------------------------------
def init(self):
with self.lock:
self.layers_loaded = self.max_layers
self.initialized = True
self.vertex_buffer = numpy2vbo(self.vertices, use_vbos = self.use_vbos)
self.vertex_color_buffer = numpy2vbo(self.colors, use_vbos = self.use_vbos) # each pair of vertices shares the color
self.initialized = True
def display(self, mode_2d=False):
with self.lock:
glPushMatrix()
glTranslatef(self.offset_x, self.offset_y, 0)
glEnableClientState(GL_VERTEX_ARRAY)
......@@ -859,12 +864,15 @@ class GcodeModelLight(Model):
else:
glColorPointer(4, GL_FLOAT, 0, self.vertex_color_buffer.ptr)
# Prevent race condition by using the number of currently loaded layers
max_layers = self.layers_loaded
start = 0
if self.num_layers_to_draw <= self.max_layers:
if self.num_layers_to_draw <= max_layers:
end_prev_layer = self.layer_stops[self.num_layers_to_draw - 1]
else:
end_prev_layer = -1
end = self.layer_stops[min(self.num_layers_to_draw, self.max_layers)]
end = self.layer_stops[min(self.num_layers_to_draw, max_layers)]
glDisableClientState(GL_COLOR_ARRAY)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment