fix h_vertex being kept after deleting shape, causing a crash if used (#832)

Steps to reproduce this particular issue:

1. draw a box
2. select the box
3. hover over one of the corners as if you want to resize the box (no click needed)
4. press DEL to delete the box
5. left click on the canvas

Note there are two more destructive operations on the canvas' `shape` in
`undo_last_line` and `reset_all_lines`, but former is dead code and latter
I don't know how to trigger. Thus I can't be sure un-highlighting will not
lead to visual glitches.

There are other potential fixes, e.g. checking in `selected_vertex`. I can
rework the patch, but then again, the fix is so straight forward that telling
me is probably more effort than just rewriting it.

See #750
See #605
This commit is contained in:
Stefan Breunig 2021-12-27 05:48:39 +01:00 committed by GitHub
parent 39ecb789a7
commit 9f2765e97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,7 +97,8 @@ class Canvas(QWidget):
self.prev_point = QPointF() self.prev_point = QPointF()
self.repaint() self.repaint()
def un_highlight(self): def un_highlight(self, shape=None):
if shape == None or shape == self.h_shape:
if self.h_shape: if self.h_shape:
self.h_shape.highlight_clear() self.h_shape.highlight_clear()
self.h_vertex = self.h_shape = None self.h_vertex = self.h_shape = None
@ -463,6 +464,7 @@ class Canvas(QWidget):
def delete_selected(self): def delete_selected(self):
if self.selected_shape: if self.selected_shape:
shape = self.selected_shape shape = self.selected_shape
self.un_highlight(shape)
self.shapes.remove(self.selected_shape) self.shapes.remove(self.selected_shape)
self.selected_shape = None self.selected_shape = None
self.update() self.update()