Skip to content

Commit 788266e

Browse files
committed
Protecting property widget exception when a label returns an invalid data tuple for the current selected property label: Sentry reported this error: OPENSHOT-43. This also fixes a regression related to updating ObjectDetector and Tracker objects.
1 parent 8ff253e commit 788266e

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

src/windows/models/properties_model.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
434434
property_type = property[1]["type"]
435435
property_key = property[0]
436436
object_id = property[1]["object_id"]
437+
objects = {}
437438
clip_id, item_type = item.data()
438439

439440
# Get value (if any)
@@ -478,12 +479,16 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
478479
# Get effect object
479480
c = Effect.get(id=clip_id)
480481

481-
if c:
482+
if c and c.data:
482483

483484
# Create reference
484485
clip_data = c.data
485486
if object_id:
486-
clip_data = c.data.get('objects').get(object_id)
487+
objects = c.data.get('objects', {})
488+
clip_data = objects.pop(object_id, {})
489+
if not clip_data:
490+
log.debug("No clip data found for this object id")
491+
return
487492

488493
# Update clip attribute
489494
if property_key in clip_data:
@@ -616,9 +621,12 @@ def value_updated(self, item, interpolation=-1, value=None, interpolation_detail
616621
has_waveform = True
617622

618623
# Reduce # of clip properties we are saving (performance boost)
619-
clip_data = {property_key: clip_data.get(property_key)}
620-
if object_id:
621-
clip_data = {'objects': {object_id: clip_data}}
624+
if not object_id:
625+
clip_data = {property_key: clip_data.get(property_key)}
626+
else:
627+
# If objects dict detected - don't reduce the # of objects
628+
objects[object_id] = clip_data
629+
clip_data = {'objects': objects}
622630

623631
# Save changes
624632
if clip_updated:
@@ -766,7 +774,7 @@ def set_property(self, property, filter, c, item_type, object_id=None):
766774
# Append ROW to MODEL (if does not already exist in model)
767775
self.model.appendRow(row)
768776

769-
else:
777+
elif name in self.items and self.items[name]["row"]:
770778
# Update the value of the existing model
771779
# Get 1st Column
772780
col = self.items[name]["row"][0]

src/windows/video_widget.py

+26-21
Original file line numberDiff line numberDiff line change
@@ -475,25 +475,26 @@ def paintEvent(self, event, *args):
475475
raw_properties_effect = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
476476
# Get properties for the first object in dict. PropertiesJSON should return one object at the time
477477
tmp = raw_properties_effect.get('objects')
478-
obj_id = list(tmp.keys())[0]
479-
raw_properties_effect = raw_properties_effect.get('objects').get(obj_id)
480-
481-
# Check if the tracked object is visible in this frame
482-
if raw_properties_effect.get('visible'):
483-
if raw_properties_effect.get('visible').get('value') == 1:
484-
# Get the selected bounding box values
485-
rotation = raw_properties_effect['rotation']['value']
486-
x1 = raw_properties_effect['x1']['value']
487-
y1 = raw_properties_effect['y1']['value']
488-
x2 = raw_properties_effect['x2']['value']
489-
y2 = raw_properties_effect['y2']['value']
490-
self.drawTransformHandler(
491-
painter,
492-
sx, sy,
493-
source_width, source_height,
494-
origin_x, origin_y,
495-
x1, y1, x2, y2,
496-
rotation)
478+
if tmp:
479+
obj_id = list(tmp.keys())[0]
480+
raw_properties_effect = raw_properties_effect.get('objects').get(obj_id)
481+
482+
# Check if the tracked object is visible in this frame
483+
if raw_properties_effect.get('visible'):
484+
if raw_properties_effect.get('visible').get('value') == 1:
485+
# Get the selected bounding box values
486+
rotation = raw_properties_effect['rotation']['value']
487+
x1 = raw_properties_effect['x1']['value']
488+
y1 = raw_properties_effect['y1']['value']
489+
x2 = raw_properties_effect['x2']['value']
490+
y2 = raw_properties_effect['y2']['value']
491+
self.drawTransformHandler(
492+
painter,
493+
sx, sy,
494+
source_width, source_height,
495+
origin_x, origin_y,
496+
x1, y1, x2, y2,
497+
rotation)
497498
else:
498499
self.drawTransformHandler(
499500
painter,
@@ -1055,10 +1056,14 @@ def mouseMoveEvent(self, event):
10551056
if self.transforming_effect_object.info.has_tracked_object:
10561057
# Get properties of effect at current frame
10571058
raw_properties = json.loads(self.transforming_effect_object.PropertiesJSON(clip_frame_number))
1059+
objects = raw_properties.get('objects', {})
1060+
if not objects:
1061+
return
1062+
10581063
# Get properties for the first object in dict.
10591064
# PropertiesJSON should return one object at the time
1060-
obj_id = list(raw_properties.get('objects').keys())[0]
1061-
raw_properties = raw_properties.get('objects').get(obj_id)
1065+
obj_id = list(objects.keys())[0]
1066+
raw_properties = objects.get(obj_id)
10621067

10631068
if not raw_properties.get('visible'):
10641069
self.mouse_position = event.pos()

src/windows/views/properties_tableview.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ def mouseMoveEvent(self, event):
192192
self.selected_item = model.item(row, 1)
193193

194194
# Is the user dragging on the value column
195-
if self.selected_label and self.selected_item:
195+
if self.selected_label and self.selected_item and \
196+
self.selected_label.data() and type(self.selected_label.data()) == tuple:
196197
# Ignore undo/redo history temporarily (to avoid a huge pile of undo/redo history)
197198
get_app().updates.ignore_history = True
198199

@@ -344,7 +345,7 @@ def doubleClickedCB(self, model_index):
344345
selected_label = model.item(row, 0)
345346
self.selected_item = model.item(row, 1)
346347

347-
if selected_label:
348+
if selected_label and selected_label.data() and type(selected_label.data()) == tuple:
348349
cur_property = selected_label.data()
349350
property_type = cur_property[1]["type"]
350351

@@ -436,23 +437,14 @@ def contextMenuEvent(self, event):
436437
_ = get_app()._tr
437438

438439
# If item selected
439-
if selected_label:
440+
if selected_label and selected_label.data() and type(selected_label.data()) == tuple:
441+
cur_property = selected_label.data()
442+
440443
# Clear menu if models updated
441444
if self.menu_reset:
442445
self.choices = []
443446
self.menu_reset = False
444447

445-
# Get data from selected item
446-
try:
447-
cur_property = self.selected_label.data()
448-
except Exception:
449-
log.debug('Failed to access data on selected label widget')
450-
return
451-
452-
if type(cur_property) != tuple:
453-
log.debug('Failed to access valid data on current selected label widget')
454-
return
455-
456448
property_name = cur_property[1]["name"]
457449
self.property_type = cur_property[1]["type"]
458450
points = cur_property[1]["points"]

0 commit comments

Comments
 (0)